Despite the easy an clean way to write both, readonly, auto and private setters are things totally different.
Readonly properties are simply a fast and clean way to declare constants/statics in code:
//constants
public const int Constant = 50;
public readonly int ReadOnly = 50;
public int ConstantMethod()
{
return 50;
}
And for statics:
public static readonly int Value = 50;
public static int ValueMethod()
{
return 50;
}
Any of them is the same thing, works the same way, except for readonly, that you can initialize in constructor. Even so, that´s a matter of how you like to code, changes nothing the results.
Remembering that static readonly is for types that don´t have literals, for methods inside classes or structs. Remembering also that new invokes the constructor of a class/struct.
Auto is the placeholder of:
private int field;
public int Property
{
get
{
return field;
}
set
{
field = value;
}
}
//In the auto property case, the "field" field is supressed, but it´s still
//there.
public int Property {get; set;}
So, private setters comes in auto properties, in any of this examples above. The keyword to considerate is private.
private, internal, protected and public are access keywords. So, if you declare:
public int Property { get; private set; }
You just are saying that you want that the "set" part of Property can be changed only for the class itself.
public int Property { get; protected set; }
Say that the "set" part of Property can be changed only by the class itself or for nested class of the base class. Also:
private int Property { get; set; }
public int Property {private get; private set; }
Both are the same. This is because the modifier that goes with the Property itself reflects in both "get" and "set" parts.