首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

要对一个Exception进行继承,怎么写参数为type的方法,有示例代码 多谢

2013-01-17 
要对一个Exception进行继承,如何写参数为type的方法,有示例代码 谢谢public class ExceptionUndefinedEnum

要对一个Exception进行继承,如何写参数为type的方法,有示例代码 谢谢


    public class ExceptionUndefinedEnumConditions : Exception
    {
        public ExceptionUndefinedEnumConditions(Type type)
        {
            if (type != null)
            {
                base.Message = type.ToString();
            }
            else
            {
                this.Message = "Type Undefined";
            }

        }
    }

我要自定义一个错误,然后传一个Type进来,但我上面的定法不行
应该如何写?
谢谢
[解决办法]
你现在什么问题 base.Message 是只读的,不能赋值
[解决办法]

 public class ExceptionUndefinedEnumConditions : Exception
    {
        public new string Message
        {
            get;
            set;
        }

        public ExceptionUndefinedEnumConditions(Type type)
        {           
            if (type != null)
            {
                this.Message = type.ToString();
            }
            else
            {
                this.Message = "Type Undefined";
            }
        }
    }

[解决办法]
如果你需要保留基类的消息,你可以再定义一个属性嘛。

热点排行