user1298925
user1298925

Reputation: 2424

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 ? 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")]

Upvotes: 2

Views: 1880

Answers (4)

Bas
Bas

Reputation: 27105

They are called Attributes and provide metadata for your classes.

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.

Upvotes: 3

dav_i
dav_i

Reputation: 28137

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.

Upvotes: 1

SWalters
SWalters

Reputation: 3704

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

Upvotes: 1

Tim Ebenezer
Tim Ebenezer

Reputation: 2724

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

Upvotes: 2

Related Questions