Instead of the wrong private int maxTime { public get; public set; } private int maxTime { public get; public set; } private int maxTime { public get; public set; } , you can write a property that will fill the private field:
private int maxTime; public int MaxTime { get { return maxTime; } set { maxTime = value; } }
This is useful when you want to apply logic when getting or setting the maxTime value. if not, then a simple shorthand property will do:
public int MaxTime { get; set; }
You can create a property that has a public recipient but a private setter, for example:
public int MaxTime { get; private set; }
This is useful for readonly properties, and usually the property is populated in the constructor of the class.
You can even create a property in which the setter is public, but getter is private, although I canβt imagine which scenario would be useful. Moreover, code standards state that such a thing should be a method, not property. (read it)
public int MaxTime { private get; set; }
Revision 2 does not answer your question.
the first code never changes the private int maxTime , and the second -. However, if you only use the maxTime property inside your class, then they are functionally equivalent.
Update:
Since C # 6 you can write shorthand properties without a setter:
public int MaxTime {get;}
These properties can only be initialized in the constructor or hardcoded as follows: (also a new C # 6 function)
public int MaxTime {get;} = DateTime.Now;
This is useful for immutable properties (unlike readonly properties, the value of such a property cannot change even inside the hosting class after initialization.