C#.NET - Trying to understand square bracket syntax in DataSource definition

jdana used Ask the Experts™
I’m still in the process of getting up to speed with C#.  I found this definition of the DataSource property in System.Windows.Forms.dll.  Can someone tell me what’s up with the square bracket notation above public object DataSource { get; set; }?  I recognize there’s a lot of code there.  I’m simply trying to get a handle on the square brackets.
// Summary:
//     Gets or sets the data source that the connector binds to.
// Returns:
//     An System.Object that acts as a data source. The default is null.
public object DataSource { get; set; }

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Those are attributes, and they affect the way the compiler and/or runtime deals with the code. Attributes can be used in many different ways, so it's difficult to give you an all-encompassing definition. For example, when performing XML serialization, you can instruct the runtime to not include an arbitrary property by tagging it with the XmlIgnore attribute:

public class SomeClass
    public string SomeProperty { get; set; }

Open in new window

Another example is that of using Windows API calls. To import a library, you can use the DllImport attribute:

static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

Open in new window

So it depends on the attribute as to what the attribute affects.



Thanks for the superlative description.  I appreciate it.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial