I have seen this kind of code in C#:
private int id {get;set;}
but I would only create getter for the field, because if there is get and set for it is the same as public field is the only way is:
public int getId(){return id;}
How to automatically generate only getters in VS2010?
What you have implemented is known as an
Automatic Propertythey look like this:Automatic properties merely syntactical sugar and in reality, provide a succinct, quick way to implement this code:
You could disregard automatic properties, using manual proeprties and simply remove the
get. Or use automatic properties and make the property’s value read only to external members by marking thegetwith the private access modifier:The code you say you would usually use, is never really needed in C# because properties, in reality are just methods in disguise and should be used as a better convention: