Question

The MSDN documentation about the DataMemberAttribute class shows a example below.

Sometimes brackets are set and sometimes are not. What is the reason behind?

Example:

[DataMember()]
    public string FirstName;

 [DataMember]
    public string LastName
    {
        get { return LastNameValue; }
        set { LastNameValue = value; }
    }
Was it helpful?

Solution

This is a C# syntax issue. It has nothing to do with these particular classes.

Brackets are optional for attributes if you do not pass arguments to the constructor of the attribute.

I recommend that you decide which style you like and stick to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top