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?

  1. When is a property not a property?
  2. When does a property defies the rules of KISS?
  3. Why waste time with meaningless code, if your property doesn't do anything why not use a public variable?
  4. Should we just forget about variables and only use properties?
  5. 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.

kick it on DotNetKicks.com