如题

解决方案 »

  1.   

    Propery是指你设定的类字段访问权限,如
    Class Test
    {
        private string name;
       
        public string Name
        {
           get
           {
              return name;
            }
           set
           {
             name =value;
           }
        }
    }
    通过此来限制字段的读写权限以及合法性检查等。Attribute是指为类附加的说明信息,与注释不同,这些说明信息是给机器看的,并能影响机器的执行,具体应用如下:
    1.影响编译器,相当于条件编译
    2.调用API函数时,要用Attribute申明是.Net Framework之外的函数
    3.自定义Attribute,用于描述对应类或方法,也就是传说中.net是自我描述的功能
    4.还是对机器说明这个类有什么用的,机器看到后就会采取相应的动作,
    如[seriablae],[webservice],[TestFixture]
      

  2.   

    昨天在java社区里也看到了一样的问题。在.NET里面Attribute是一个抽象类,可以理解为一种描述类,它用来约束被描述的声明或者对象等。而Property应该是一个概念,可以理解为类型的属性,它是一个语言的关键字,给类的内部实现和外在表现提供支持。
    .NET里面对Attribute的描述为:
    The common language runtime allows you to add keyword-like descriptive declarations, called attributes, to annotate programming elements such as types, fields, methods, and properties. Attributes are saved with the metadata of a Microsoft .NET Framework file and can be used to describe your code to the runtime or to affect application behavior at run time.
    Property在C#中有如下描述:
    Properties are named members of classes, structs, and interfaces. They provide a flexible mechanism to read, write, or compute the values of private fields through accessors.两种虽然在翻译上可能比较相似,但是在.NET中的意义是完全不同的。我想Java中也应该类似吧。--个人建议。
      

  3.   

    Propery是一个类的成员,而attribute是一个抽象的类,用来描述其它的对象,并可以影响到它们的运行