基本构造在C#中 - 其中被调用第一?基本

由网友(坎坷王者路)分享简介:这被称为第一 - 基构造或这里其他的东西?公共类MyExceptionClass:异常{公共MyExceptionClass(字符串消息,串extrainfo):基地(消息){这里//其他的东西}}解决方案 该基地的构造函数将首先被调用。试试吧:公共类MyBase{公共MyBase(){Console.Write...

这被称为第一 - 基构造或这里其他的东西

 公共类MyExceptionClass:异常
{
    公共MyExceptionClass(字符串消息,串extrainfo):基地(消息)
    {
        这里//其他的东西
    }
}
 

解决方案

该基地的构造函数将首先被调用。

试试吧:

 公共类MyBase
{
  公共MyBase()
  {
    Console.WriteLine(MyBase);
  }
}

公共类MyDerived:MyBase
{
  公共MyDerived():基地()
  {
    Console.WriteLine(MyDerived);
  }
}
 

帮助你完全理解java中的值传递与引用传递的区别分析

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");
  }
}

阅读全文

相关推荐

最新文章