浅谈C#中子类用new与override的区别

我们先看代码和运行结果,代码: BaseClass.cs文件: public class BaseClass { public BaseClass() { Console.WriteLine(“Base Constructed Function”); } public virtual void Execute() { Console.WriteLine(“Base Virtual Execute Function”); } public virtual void Execute2() { Console.WriteLine(“Base Virtual Execute2 Function”); } } ChildClass.cs文件: public class ChildClass : BaseClass { public ChildClass() { Console.WriteLine(“Children Constructed Function”); } public override void Execute() { Console.WriteLine(“Children Execute… Continue reading 浅谈C#中子类用new与override的区别