000: // Versioning\versioning.cs 001: public class MyBase 002: { 003: public virtual string Meth1() 004: { 005: return "MyBase-Meth1"; 006: } 007: public virtual string Meth2() 008: { 009: return "MyBase-Meth2"; 010: } 011: public virtual string Meth3() 012: { 013: return "MyBase-Meth3"; 014: } 015: } 016: 017: class MyDerived : MyBase 018: { 019: public override string Meth1() 020: { 021: return "MyDerived-Meth1"; 022: } 023: public new string Meth2() 024: { 025: return "MyDerived-Meth2"; 026: } 027: public string Meth3() // 系统在这里将会有一个警告,并且将会隐藏方法Meth3() 028: 029: 030: { 031: return "MyDerived-Meth3"; 032: } 033: 034: public static void Main() 035: { 036: MyDerived mD = new MyDerived(); 037: MyBase mB = (MyBase) mD; 038: 039: System.Console.WriteLine(mB.Meth1()); 040: System.Console.WriteLine(mB.Meth2()); 041: System.Console.WriteLine(mB.Meth3()); 042: } 043: } |
MyDerived-Meth1 MyBase-Meth2 MyBase-Meth3 |
MyDerived-Meth1 MyDerived-Meth2 MyDerived-Meth3 |
class Base {} class Derived: Base { public void F() {} } 和: class Base { public void F() {} } class Derived: Base { public void F() {} } |