Features of C# Basic Grammar



1. What is a feature

A feature is a language structure that allows us to add metadata to the program's assembly.

Property name using Pascalnaming, and with Attributethe suffix ending. (Pascal naming method requires that all English names begin with capital letters)



2. Application characteristics

The feature fragment, surrounded by square brackets, includes the feature name and feature parameter list. The parameter list is actually equivalent to a constructor.

       [Obsolete("这个方法是旧方法,请使用新方法")]
        public string Get() {
    
    
            return "你好";
        }



3. Commonly used encapsulated features

A certain method is deprecated. When it is referenced, there is a prompt. If the second parameter is true, then this will report an error instead of a warning when it is used.

    [Obsolete("这个方法是旧方法,请使用新方法",true)]

When debugging, skip this step without entering.

    [DebuggerStepThrough]



Four. Custom features

Characteristic is actually a class, he inherited from System.Attributethis class, and use Pascalnaming

     class MyAttribute:System.Attribute
    {
    
    
    }

When using the feature, you can use the short name, that is, remove the attribute.

Guess you like

Origin blog.csdn.net/zhaozhao236/article/details/113532368