Im not sure because in Java getter/setter are looking a little bit different but whats the “c# way” to code this stuff?
Option a.)
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int time;
public int Time
{
get { return time; }
set { time = value; }
}
b.)
private string _name;
private int _time;
public string name
{
get { return _name; }
set { _name = value; }
}
public int time
{
get { return _time; }
set { _time = value; }
}
c.)
public string name {get; set;}
public int time {get; set;}
Ok there are some examples. What would look better? Should I write all the private variable declarations first then the properties or should I group my variable and property declaration next to each other.
How about d, following .NET naming conventions:
Don’t bother writing the property manually yourself unless you do something non-trivial in it.
If you do write the property implementation manually, it’s up to you how you name the private variable. Personally I’d use:
… but if you want to use underscores, that’s your prerogative.
As for ordering of members – that’s even more your own choice. Assuming you’re working with a team, talk with the team and see what the local convention is.