C# base 与 this
作者:互联网
base
用于派生类中访问基类成员如:调用基类上已被重写的方法
:创建派生类时调用基类构造函数
1 public class Person 2 { 3 Person() 4 { 5 Console.WriteLine("初始化"); 6 } 7 protected string name = "John"; 8 9 public virtual void GetInfo() 10 { 11 Console.WriteLine("Name: {0}", name); 12 } 13 } 14 class Employee : Person 15 { 16 public DerivedClass() : base() { } //调用基类构造函数 17 18 public string id = "01"; 19 public override void GetInfo() // 继承重写基类方法 20 { 21 base.GetInfo(); // 调用基类方法 22 Console.WriteLine("Employee ID: {0}", id); 23 } 24 }
标签:Console,GetInfo,C#,base,WriteLine,基类,public 来源: https://www.cnblogs.com/CatZone/p/15136483.html