zoukankan      html  css  js  c++  java
  • obsolete 特性 的使用

    [Obsolete("已经过时的",true)]  //失败,  "已经过时的"文字部分可以是任何我们需要的描述!

    [Obsolete("已经过过时的",false)] //警告

    Obsolete 特性,在C#中作为特性关键字存在。

    如果我们的某一个属性,方法或类不是最优的,那么我们可以在此**前加上开头两句话 的任一句,根据需要确认是生成错误,还是警告用户。

    e-g:

    public class MyClass
        {      
            [Obsolete("这个属性不要用了", true)]
            public string Str
            {
                get;
                set;
            }

            public string Attribute
            {
                get;
                set;
            }
        }

    实例化,调用:

       MyClass my = new MyClass();

            protected void test()
            {
                my.Str = "test";//报错--已过时:“这个属性不要用了”
                my.Attribute = "test1"; //可以正常赋值
            }

  • 相关阅读:
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
  • 原文地址:https://www.cnblogs.com/hometown/p/2778157.html
Copyright © 2011-2022 走看看