您的位置:首页 > 编程语言 > C#

C# 类,私有公有属性,继承

2017-12-07 18:54 253 查看
class BaseFile
{
//字段、属性、构造函数、函数、索引器
//私有字段
private string _filePath;
public string FilePath //快捷键 ctrl+R+E
{
get { return _filePath; }
set { _filePath = value; }
}

//自动属性 快捷键 prop+两下tab
public string FileName { get; set; }

//构造函数
public BaseFile(string filePath, string fileName)
{
this.FilePath = filePath;
this.FileName = fileName;
}

//设计一个函数 用来打开指定的文件
public void OpenFile()
{
ProcessStartInfo psi = new ProcessStartInfo(this.FilePath + "\\" + this.FileName);
Process pro = new Process();
pro.StartInfo = psi;
pro.Start();
}
}

继承:
class TxtFile : BaseFile
{
//因为子类会默认调用父类无参数的构造函数

public TxtFile(string filePath, string fileName) : base(filePath, fileName)
{ }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c#