Possible Duplicate:
What is the difference between a field and a property in C#?
Difference between Property and Field in C# .NET 3.5+
Some time ago I inherited a C# web app wherein most class members that could be fields are defined as properties in one of the following two manners:
private Guid id;
public Guid Id
{
get { return id; }
set { id = value; }
}
public int someValue{ get; set; }
Namely, the getters/setters don't do anything other than ferry a value to/from a private field. In these cases, is there an advantage [or justification] for building these members out as properties vs. fields? And vice versa?
Would I be violating any unspoken rules or best practices by changing them to fields? Is there a notable performance difference -- for instance, incrementing someValue
for a list of N objects one way or the other? (My current understanding is that field access is necessarily less complex [and efficient].)