您的位置:首页 > 编程语言 > C#

C#中base两种用法

2012-08-07 09:08 246 查看
1、调用基类中的重名方法

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# string class output