简体   繁体   English

类名的括号在C#类中的含义是什么

[英]What do brackets around a class name mean in a C# class

As a beginner in the world of .NET and C# I dont know what does it mean when I see the following syntax at the beginning of a .CS file ? 作为.NET和C#世界的初学者,我不知道当我在.CS文件的开头看到以下语法时它意味着什么? I am confused about the meaning of the brackets around the names? 我对名字周围括号的含义感到困惑? Thanks in advance for your help. 在此先感谢您的帮助。

   [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "55.555.5.555")]
   [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "5.5.34444.55")]
   [System.SerializableAttribute()]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]

What you're seeing there is what is known as an 'Attribute'. 您所看到的就是所谓的“属性”。 This describes something about the class, and can allow other pieces of code to interact with that class in specific ways. 这描述了关于类的一些内容,并且可以允许其他代码片段以特定方式与该类进行交互。

You can find out more about attributes here: http://msdn.microsoft.com/en-us/library/aa288454(v=vs.71).aspx 您可以在此处找到有关属性的更多信息: http//msdn.microsoft.com/en-us/library/aa288454(v = vs.71).aspx

In the examples you showed, they're used to designate attributes above the declaration of the entity to which they apply: 在您展示的示例中,它们用于指定它们适用的实体声明之上的属性:

http://msdn.microsoft.com/en-us/library/z0w1kczw.aspx http://msdn.microsoft.com/en-us/library/z0w1kczw.aspx

These are Attributes . 这些是属性

Attributes provide a powerful method of associating metadata, or declarative information, with code (assemblies, types, methods, properties, and so forth). 属性提供了一种将元数据或声明性信息与代码(程序集,类型,方法,属性等)相关联的强大方法。 After an attribute is associated with a program entity, the attribute can be queried at run time by using a technique called reflection. 在属性与程序实体关联后,可以使用称为反射的技术在运行时查询该属性。

They are called Attributes and provide metadata for your classes. 它们被称为Attributes并为您的类提供元数据。

For example, the SerializableAttribute lets some classes know that your object can be written to disk or sent over a network connection to another program. 例如, SerializableAttribute允许某些类知道您的对象可以写入磁盘或通过网络连接发送到另一个程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM