Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is [] brackets in .net? [duplicate]

i have seen [] such brackets in c# very very rarely but when i start to learn asp.net i have seen them many times but still i couldn't understand what they does ?

They are not part of code as using for arrays.For example [webmethods] which is just over the methods or there are some over classes. Are they part of .net or they are just tell something to CLR ? or ?

like image 325
Freshblood Avatar asked Jun 03 '10 18:06

Freshblood


3 Answers

They are used to put Attributes on classes or methods (or other stuff). That way, you can attach data to classes that should not be part of the actual class. You can read more on them here

like image 111
Jouke van der Maas Avatar answered Oct 17 '22 23:10

Jouke van der Maas


[] brackets are an operator in C#. The link contains more detailed information and examples of what I summarized below.

They are used for:

  • Array type definition
  • Access an element of an array
  • They can be used as indexer parameters for any type
  • They can be used to specify attributes <-- This seems like what you are asking about
  • They can be used for unsafe code to index an offset from a pointer
like image 23
Brian R. Bondy Avatar answered Oct 17 '22 22:10

Brian R. Bondy


You're seeing .Net attributes (VB or C#), which can annotate types and members.

like image 21
SLaks Avatar answered Oct 17 '22 22:10

SLaks