.NET[C#]C#中如何调用基类的构造函数?

.NET 作者: Rector 发布时间: 2018-01-14 09:50:58 11阅读 0评论 0收藏 收藏本文

示例一

public class MyExceptionClass : Exception
{
    public MyExceptionClass(string message, string extrainfo) : base(message)
    {
        //other stuff here
    }
}

示例二

class MyExceptionClass : Exception
{
     public MyExceptionClass(string message, string extraInfo) : 
         base(ModifyMessage(message, extraInfo))
     {
     }

     private static string ModifyMessage(string message, string extraInfo)
     {
         Trace.WriteLine("message was " + message);
         return message.ToLowerInvariant() + Environment.NewLine + extraInfo;
     }
}

示例三



public class MyException : Exception
{
    public MyException() { }
    public MyException(string msg) : base(msg) { }
    public MyException(string msg, Exception inner) : base(msg, inner) { }
}

转载请注明:图享网 » .NET[C#]C#中如何调用基类的构造函数?

分享扩散:

文章评论

获取验证码