What is the thing in square brackets that comes before a C# class declaration called?
C#C# Problem Overview
What is the [something]
in
[something]
public class c1 {
}
called in C#? What does it do?
C# Solutions
Solution 1 - C#
That's an Attribute.
Solution 2 - C#
This is known as an attribute application / usage. It associates an instance of a given Attribute
with a type. These are user definitable items. For example
[AttributeUsage(AttributeTargets.All)]
public class ExampleAttribute : System.Attribute {
public ExampleAttribute() { }
}
This is an attribute which can be applied on ever place an attribute is legal
// Assembly level
[assembly: Example]
// Class
[Example]
public class C1 {
// Field
[Example]
public int m_field;
// Method
[Example]
public void Test() { }
}
More locations are possible but hopefully this gets the general idea across. You may also want to check out this tutorial
Solution 3 - C#
Its called an Attribute. A class that ends in "Attribute", and inherits from Attribute:
public class SomethingAttribute : Attribute {
}
If you are creating one, be sure to look up the AttributeUsageAttribute class.
Solution 4 - C#
C# Attributes. Please see this documentation.