RSS
热门关键字:
当前位置 :| 主页>net development>

Of the key word in C# : Base, This

来源: 作者:Stand originally 时间:2008-12-21 Tag: 点击:

In C#Key word: Base, This. Base key word uses at from derive kind in visit radical kind member: Call base kind the method that goes up to already was rescripted by other method.

Appoint found derive kind should call when example base kind tectonic function.

Base kind the visit is constructing only method of function, example or example attribute visit implement in undertake.

   Give typical examples:

In derive kind in call base kind method.

It is to cite below extract:
/ / Base key word
/ / visit radical kind member
Using System;
Public Class BaseClass
{
Protected String _className = "BaseClass" ;
Public Virtual Void PrintName()
{
Console.WriteLine("Class Name:&Nbsp;{0}" , _className);
}
}
Class DerivedClass:&Nbsp;BaseClass
{
Public String _className = "DerivedClass" ;
Public Override Void PrintName()
{
Console.Write("The BaseClass Name Is {0}" );
/ / call base kind method
Base.PrintName();
Console.WriteLine("This DerivedClass Is {0}" , _className);
}
}
Class TestApp
{
Public Static Void Main()
{
DerivedClass Dc = New DerivedClass();
Dc.PrintName();
}
}
/ **//*

Console output:

The BaseClass Name Is BaseClass

This DerivedClass Is DerivedClass

*/

In derive kind in call base kind tectonic function.

It is to cite below extract:
/ / Keywords_base2.cs
Using System;
Public Class BaseClass
{
Int Num;
Public BaseClass()
{
Console.WriteLine("in BaseClass()" );
}
Public BaseClass(int I)
{
Num = I;
Console.WriteLine("in BaseClass(int {0})" , num);
}
}
Public Class DerivedClass:&Nbsp;BaseClass
{
/ / this are tectonic implement call BaseClass.BaseClass()
Public DerivedClass() :&Nbsp;base()
{
}
/ / this are tectonic implement call BaseClass.BaseClass(int I)
Public DerivedClass(int I) :&Nbsp;base(i)
{
}
Static Void Main()
{
DerivedClass Dc = New DerivedClass();
DerivedClass Dc1 = New DerivedClass(1);
}
}
/ **//*

Console output:

In BaseClass()

In BaseClass(1)

*/


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册