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)
{ }
}