C#中base两种用法
2012-08-07 09:08
246 查看
1、调用基类中的重名方法
2、调用基类的构造方法
public class Person { protected string ssn = "444-55-6666"; protected string name = "John L. Malgraine"; public virtual void GetInfo() { Console.WriteLine("Name: {0}", name); Console.WriteLine("SSN: {0}", ssn); } } class Employee : Person { public string id = "ABC567EFG"; public override void GetInfo() { // Calling the base class GetInfo method: base.GetInfo(); Console.WriteLine("Employee ID: {0}", id); } } class TestClass { static void Main() { Employee E = new Employee(); E.GetInfo(); } } /* Output Name: John L. Malgraine SSN: 444-55-6666 Employee ID: ABC567EFG */
2、调用基类的构造方法
ublic class ActionCancelEventArgs : System.ComponentModel.CancelEventArgs { public ActionCancelEventArgs() : this(false) {} public ActionCancelEventArgs(bool cancel) : this(false, String.Empty) {} public ActionCancelEventArgs(bool cancel, string message) : base(cancel) { this.message = message; } public string Message{ get; set;} }
相关文章推荐
- C# 中 this 和 base 的用法
- 转:C#中base关键字的几种用法
- C# 中用 Sqlparameter 的两种用法
- C#:base与this关键字用法小结
- C# Base关键字的用法
- C#中base的用法
- [c#]两种Transaction和用法
- 说一说C#关键字Default的两种用法
- C#中seal关键字两种用法
- C# Base关键字的用法
- [C#]委托的两种用法
- c# 的继承,继承类实例化的时候,会先调用基类的构造函数,然后再调用自己的构造函数,base 的用法,有override和没有override的区别
- C#中base的用法
- C# this、base的两种用法
- C# default 的两种用法
- C#中base关键字的几种用法
- C# :base的用法(冒号后面的base)
- 【源码】c# pagebase 用法提升
- c# base关键字的用法
- C#里面base的有趣用法1