扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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() {} } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者