zoukankan      html  css  js  c++  java
  • 你必须知道的.Net 【特 性】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 等,有时间可以深入研究。

  • 相关阅读:
    windows下cmd命令行上传代码到github的指定库
    Navicat Premium 12.1.11.0安装与激活
    windows部署Apollo
    C#事件-使用事件需要的步骤
    C#委托和事件
    C#事件委托概念
    C#中委托和事件的区别
    C#委托与事件
    C#细说多线程
    C# 堆栈(Stack)和队列(Queue)
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/10331861.html
Copyright © 2011-2022 走看看