[b]一、调用基类已被派生类重写的方法[/b]
public class Father
{
public virtual void Say()
{
Console.WriteLine("Father Say");
}
}
public class Son : Father
{
public override void Say()
{
base.Say();
Console.WriteLine("Son Say");
}
}
调用:
Son s = new Son();
s.Say();
执行代码会先输出Father Say,然后输出Son Say。
[b]二、指定派生类实例时调用基类的构造函数[/b]
public class Father
{
public string Name { get; set; }
public Father()
{
Name = "Father";
}
}
public class Son : Father
{
public Son()
: base()
{
}
}
创建对象:
Son s = new Son();
运行之后Son的实例Name属性为Father。
[b]三、Base在EntityFramework中的使用,如下图:[/b]
[img]http://files.jb51.net/file_images/article/201604/2016423162513905.png[/img]
注意:base关键字不能在静态方法中使用。