Scuba Steve
Scuba Steve

Reputation: 1648

what are ["foo bar"] lines in c#?

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.

Upvotes: -1

Views: 523

Answers (3)

Myrtle
Myrtle

Reputation: 5841

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.

Upvotes: 2

BrunoLM
BrunoLM

Reputation: 100381

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.

Upvotes: 2

MacakM
MacakM

Reputation: 1820

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

Upvotes: 2

Related Questions