C# 中使用 override 和 new 关键字进行版本控制的代码
在研发之余,把写代码过程中比较常用的代码备份一下,下面的代码内容是关于C# 中使用 override 和 new 关键字进行版本控制的代码,应该是对大家有些用。
public class MyBase
{
public virtual string Meth2()
{
return "MyBase-Meth2";
}
public virtual string Meth3()
{
return "MyBase-Meth3";
}
public virtual string Meth4()
{
return "MyBase-Meth4";
}
}
class MyDerived : MyBase
{
public override string Meth2()
{
return "MyDerived-Meth2";
}
public new string Meth3()
{
return "MyDerived-Meth3";
}
public string Meth4()
{
return "MyDerived-Meth4";
}
public static void Main()
{
MyDerived mD = new MyDerived();
MyBase mB = (MyBase) mD;
System.Console.WriteLine(mB.Meth2()); System.Console.WriteLine(mB.Meth3()); System.Console.WriteLine(mB.Meth4());
}
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。