当前位置

首页 > 商务英语 > 计算机英语 > c中base的用法

c中base的用法

推荐人: 来源: 阅读: 2.75W 次

c中base的用法的用法你知道吗?下面小编就跟你们详细介绍下c中base的用法的用法,希望对你们有用。

Class="img-ratio-box" style="width: 640px;">c中base的用法

c中base的用法的用法如下:

1、调用基类中的重名方法

[csharp]

public class Person

{

protected string ssn = "444-55-6666";

protected string name = "John L. Malgraine";

public virtual void GetInfo()

{

eLine("Name: {0}", name);

eLine("SSN: {0}", ssn);

}

}

class Employee : Person

{

public string id = "ABC567EFG";

public override void GetInfo()

{

// Calling the base class GetInfo method:

nfo();

eLine("Employee ID: {0}", id);

}

}

class TestClass

{

static void Main()

{

Employee E = new Employee();

nfo();

}

}

/*

Output

Name: John L. Malgraine

SSN: 444-55-6666

Employee ID: ABC567EFG

*/

2、调用基类的构造方法

[csharp]

ublic class ActionCancelEventArgs : elEventArgs

{

public ActionCancelEventArgs() : this(false) {}

public ActionCancelEventArgs(bool cancel) : this(false, y) {}

public ActionCancelEventArgs(bool cancel, string message) : base(cancel)

{

age = message;

}

public string Message{ get; set;}

}