What is an attribute in C#?

Experience Level: Junior
Tags: C#

Answer

  • In C#, an attribute is like a tag using which you can add additional information to a class or method.
  • The attribute is applied to a class or method by writing the attribute name into the square brackets before the class or method definition.
  • In the example below you can see how the attribute Test is applied to the class Verification and attribute Obsolete is applied to the method MyMethod.
Example
namespace House 
{
  [Test]  
  class Verification 
  {
    [Obsolete]
    public static void MyMethod()
    { 
    
    }
  }
}

Comments

No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

Anonymous
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
Anonymous
e
Anonymous
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e