csharp-in-style icon indicating copy to clipboard operation
csharp-in-style copied to clipboard

Properties with backing members

Open bryancostanich opened this issue 11 years ago • 3 comments

i think that this:

public string Name {
    get { return name; }
    set { name = value; }
} protected string name;

is better than this:

string name;
public string Name {
    get { return name; }
    set { name = value; }
}

bryancostanich avatar Jan 03 '14 23:01 bryancostanich

Yes, I see the merit to this but it's also a bit baroque. If the backing field came after the property, I would definitely not put it on the same line as the closing brace of the property.

public string Name {
    get { return name; }
    set { name = value; }
}
string name;

This is especially advantageous when the property has lots of attributes...

dvdsgl avatar Jan 03 '14 23:01 dvdsgl

@bryancostanich next time please format your code snippets correctly–see how I added the fenced code blocks.

dvdsgl avatar Jan 03 '14 23:01 dvdsgl

that's fine, as long as it comes after, as it's easier to parse. i don't know if it's baroque though, i actually like it because it hides the backing field, visually. :)

bryancostanich avatar Jan 03 '14 23:01 bryancostanich