-1

So I'm coming over from Java, and I've been seeing (and using), a ton of these:

["foo bar"]
void method(param params)
{
     ..code things
}

Can someone explain to me what they are? I don't even know what they're called, so I can't manage to figure it out from documentation.

Myrtle
  • 5,761
  • 33
  • 47
Scuba Steve
  • 1,541
  • 1
  • 19
  • 47
  • 2
    Search for Attributes in C#, You can search for Data Annotations also. – Vivek Nuna Oct 22 '16 at 19:35
  • if you hover the mouse over one in VS, it'll tell you it's a `SomethingOrOtherAttribute`. After a while you should notice that every single one will have "Attribute" on the end. If you right click on it, you can click "Go To Definition" on the context menu to learn more about it. You can also just google `SomethingOrOtherAttribute`, or whatever the name of it is, to find out what MSDN has to say. It's gonna say, first and foremost, that it's an attribute. So next time, you'll know how to find your own answer to questions like this: Hover, Go to Definition, and Google. – 15ee8f99-57ff-4f92-890c-b56153 Oct 22 '16 at 19:45

3 Answers3

2

They are called .NET Attributes. You can read about it for example here: What are attributes in .NET?

Community
  • 1
  • 1
MacakM
  • 1,804
  • 3
  • 23
  • 46
2

They are attributes. You can use them to decorate your code. The libraries providing the attributes usually use reflection to get this decorated (meta) information from your code at runtime.

For example, the XmlSerializer uses them a lot.

Graham
  • 7,431
  • 18
  • 59
  • 84
Myrtle
  • 5,761
  • 33
  • 47
2

They are called Attributes.

There are many uses, such as:

  • Declare tests methods
  • Add description on enum values
  • Dependency Injection with MEF
  • You can do things with reflection

and so on.

BrunoLM
  • 97,872
  • 84
  • 296
  • 452