3

Can somone explian what the square brackets in the following code do?

public interface IType : IEditor
    {
        #region Properties

        /// <summary>
        /// Genre ID
        /// </summary>
        int GenreID { get; set; }

        /// <summary>
        /// Genre name
        /// </summary>
        [Required]
        [DisplayName("Unique System name")]
        string Name { get; set; }

        /// <summary>
        /// Url Genre safe name
        /// </summary>
        [DisplayName("Unique Url Safe name")]
        string UrlSafeName { get; set; }

        #endregion

    }
Adam Robinson
  • 177,794
  • 32
  • 275
  • 339
Milligran
  • 2,961
  • 8
  • 41
  • 55
  • 5
    They keep the VB-ers out of our code base! But seriously, you find them around attributes and array declarations: `int[]` – Adam Houldsworth Mar 15 '12 at 14:55
  • The first Bing result for "what square brackets in C# do" is [MSDN documenation](http://msdn.microsoft.com/en-us/library/a3hd7ste.aspx) on uses of square brackets in C#, including their use as attributes (the use you are showing). [Here](http://stackoverflow.com/questions/726029/attributes-in-c-sharp) is a good explanation of attributes. – Adam Mihalcin Mar 15 '12 at 14:56
  • 3
    How on earth is this closed as "not a real question"? It's the first Google result for "c# square brackets before method definition" and answered what I wanted to know. – colincameron Sep 20 '16 at 15:10

4 Answers4

4

Attributes. See the reference article below.

C# Attributes

rrrr-o
  • 2,357
  • 1
  • 23
  • 52
4

They are applying attributes to the property

Darren Kopp
  • 74,695
  • 9
  • 74
  • 91
  • 1
    I was wondering about how to reward people. I am use to expert exchange where I award points. Didnt see that option in Stackoverflow – Milligran Mar 15 '12 at 15:07
1

It is a syntax for applying attributes.

For more details check this : http://msdn.microsoft.com/en-us/library/aa288454(v=vs.71).aspx

davit_gri
  • 120
  • 1
  • 8
0

See this page on MSDN http://msdn.microsoft.com/en-us/library/a3hd7ste.aspx

Trevor Pilley
  • 15,778
  • 5
  • 43
  • 59