由网友(坎坷王者路)分享简介:这被称为第一 - 基构造或这里其他的东西?公共类MyExceptionClass:异常{公共MyExceptionClass(字符串消息,串extrainfo):基地(消息){这里//其他的东西}}解决方案 该基地的构造函数将首先被调用。试试吧:公共类MyBase{公共MyBase(){Console.Write...
这被称为第一 - 基构造或这里其他的东西
? 公共类MyExceptionClass:异常
{
公共MyExceptionClass(字符串消息,串extrainfo):基地(消息)
{
这里//其他的东西
}
}
解决方案
该基地的构造函数将首先被调用。
试试吧:
公共类MyBase
{
公共MyBase()
{
Console.WriteLine(MyBase);
}
}
公共类MyDerived:MyBase
{
公共MyDerived():基地()
{
Console.WriteLine(MyDerived);
}
}
Which gets called first - the base constructor or "other stuff here"?
public class MyExceptionClass : Exception
{
public MyExceptionClass(string message, string extrainfo) : base(message)
{
//other stuff here
}
}
解决方案
The base constructor will be called first.
try it:
public class MyBase
{
public MyBase()
{
Console.WriteLine("MyBase");
}
}
public class MyDerived : MyBase
{
public MyDerived():base()
{
Console.WriteLine("MyDerived");
}
}
相关推荐
最新文章