Attribute

In this chapter you will learn:

  1. What is an attribute

Get to know attribute

You can add declarative information to a program by using an attribute. An attribute defines additional information that is associated with a class, structure, method, and so on.

An attribute is supported by a class that inherits System.Attribute. All attribute classes must be subclasses of System.Attribute. This built-in attribute AttributeUsage specifies the types of items to which the attribute can be applied.

using System.Diagnostics;
/* j a v  a2 s  .c o  m*/

class MainClass
{
    [Conditional("DEBUG")]
    public void Validate()
    {
    }
}

Next chapter...

What you will learn in the next chapter:

  1. What are the build-in C# attributes
  2. Assembly-Level Attributes
Home » C# Tutorial » Attribute
Attribute
Build-in attributes
Obsolete Attribute
Conditional Attribute
Custom Attributes
Attribute parameter
AttributeUsage
Attribute reflection