码迷,mamicode.com
首页 > 其他好文 > 详细

【特 性】Attribute

时间:2019-01-28 21:46:02      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:code   ring   时间   使用   type   row   net   ble   attribute   

 

1 AttributeUsage

    [AttributeUsageAttribute(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
    class MyNewAttribute : System.Attribute
    {
        //
    }

2 Flags

    class Program
    {
        static void Main(string[] args)
        {
            Animal animals = Animal.Dog | Animal.Cat;
            Console.WriteLine(animals.ToString());
        }
    }
    [Flags]
    enum Animal
    {
        Dog = 0x0001,
        Cat = 0x0002,
        Duck = 0x0004,
        Chicken = 0x0008
    }

3 DllImport

        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern int MessageBox(int hParent, string msg, string caption, int type);
        static void Main(string[] args)
        {
            MessageBox(0, "How to use attribute in .NET", "Anytao_net", 0);
        }

4 Serializable

  Serializable 特性表明了应用的元素可以被序列化(serializated),序列化和反序列化是另一个 可以深入讨论的话题,在此我们只是提出概念,深入的研究有待以专门的主题来呈现,限于篇幅, 此不赘述。

5 Conditional

  Conditional 特性,用于条件编译,在调试时使用。注意:Conditional 不可应用于数据成员和 属性。

还有其他的重要特性,包括:Description、DefaultValue、Category、ReadOnly、Brow erAble 等,有时间可以深入研究。

【特 性】Attribute

标签:code   ring   时间   使用   type   row   net   ble   attribute   

原文地址:https://www.cnblogs.com/kikyoqiang/p/10331861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!