c#.net中类的覆写(OverRide)
public
class
MyBase
...
{
public
virtual
string
Meth1()
...
{
return
"
MyBase-Meth1
"
;
}
public
virtual
string
Meth2()
...
{
return
"
MyBase-Meth2
"
;
}
public
virtual
string
Meth3()
...
{
return
"
MyBase-Meth3
"
;
}
}

class
MyDerived:MyBase
...
{
//
OverridesthevirtualmethodMeth1usingtheoverridekeyword:
public
override
string
Meth1()
...
{
return
"
MyDerived-Meth1
"
;
}
//
ExplicitlyhidethevirtualmethodMeth2usingthenew
//
keyword:
public
new
string
Meth2()
...
{
return
"
MyDerived-Meth2
"
;
}
//
Becausenokeywordisspecifiedinthefollowingdeclaration
//
awarningwillbeissuedtoalerttheprogrammerthat
//
themethodhidestheinheritedmemberMyBase.Meth3():
public
string
Meth3()
...
{
return
"
MyDerived-Meth3
"
;
}

public
static
void
Main()
...
{
MyDerivedmD
=
new
MyDerived();
MyBasemB
=
(MyBase)mD;
System.Console.WriteLine(mB.Meth1());
System.Console.WriteLine(mB.Meth2());
System.Console.WriteLine(mB.Meth3());
}
}
博客介绍了C#.NET中类的覆写(OverRide)相关内容,聚焦于信息技术领域中C#语言在.NET环境下类的这一特性。
710

被折叠的 条评论
为什么被折叠?



