相关疑难解决方法(0)

在C#中调用基础构造函数

如果我从一个基类继承并希望将继承类的构造函数中的某些东西传递给基类的构造函数,我该怎么做?

例如,

如果我从Exception类继承,我想做这样的事情:

class MyExceptionClass : Exception
{
     public MyExceptionClass(string message, string extraInfo)
     {
         //This is where it's all falling apart
         base(message);
     }
}
Run Code Online (Sandbox Code Playgroud)

基本上我想要的是能够将字符串消息传递给基本的Exception类.

c# inheritance constructor

1398
推荐指数
11
解决办法
98万
查看次数

标签 统计

c# ×1

constructor ×1

inheritance ×1