override virtual
Posted sky20080101
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了override virtual相关的知识,希望对你有一定的参考价值。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConstructCallVirtual { class Program { static void Main(string[] args) { B b=new B(); } } class A { public A() { Console.WriteLine("A()"); DoSth(); } public virtual void DoSth() { Console.WriteLine("A::DoSth()"); } } class B:A { public B() { Console.WriteLine("B()"); DoSth(); } public virtual void DoSth() { Console.WriteLine("B::DoSth()"); } } //A() //A::DoSth() //B() //B::DoSth() // }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConstructCallVirtual { class Program { static void Main(string[] args) { B b=new B(); } } class A { public A() { Console.WriteLine("A()"); DoSth(); } public virtual void DoSth() { Console.WriteLine("A::DoSth()"); } } class B:A { public B() { Console.WriteLine("B()"); DoSth(); } public override void DoSth() { Console.WriteLine("B::DoSth()"); } } //A() //B::DoSth() //B() //B::DoSth() // }
以上是关于override virtual的主要内容,如果未能解决你的问题,请参考以下文章