Ok, seriously, this debate must end! I strongly believe that changing a variable to a property is breaking a change! However, others feel otherwise.
Update: Yes, this debate is not valid for C# 3.0, however, the question is intended for the earlier versions of C# which is still widely used.
private string name;
public string Name
{
get
{
return name;
}
set
{
name=value;
}
}
How many times have you seen a similar snippet just like the one above, I just had a mouth battle with other developers that think otherwise about how properties should be used. The debate all started when I stated that if you have a property, you should always access the property rather than the local private variable. Anyway, the question is when should we use a property over a public variable?
- When is a property not a property?
- When does a property defies the rules of KISS?
- Why waste time with meaningless code, if your property doesn't do anything why not use a public variable?
- Should we just forget about variables and only use properties?
- When should a method be used over a property?
I've heard different arguments and there is no real conclusion on my part, I want to hear what you guys think.
