public class Const_V_Readonly{public const int I_CONST_VALUE = 2;public readonly char[] I_RO_VALUE = new Char[]{'a', 'b', 'c'};
public UpdateReadonly(){I_RO_VALUE[0] = 'V'; //perfectly legal and will update the valueI_RO_VALUE = new char[]{'V'}; //will cause compiler error}}
public static class Text {public const string ConstDescription = "This can be used.";public readonly static string ReadonlyDescription = "Cannot be used.";}
public class Foo{[Description(Text.ConstDescription)]public int BarThatBuilds \{\{ get; set; }}
[Description(Text.ReadOnlyDescription)]public int BarThatDoesNotBuild \{\{ get; set; }}}
public class Sample {private readonly string ro;
public Sample() {ro = "set";}
public Sample(string value) : this() {ro = value; // this works even though it was set in the no-arg ctor}}
public class Color{public static Color Black = new Color(0, 0, 0);public static Color White = new Color(255, 255, 255);public static Color Red = new Color(255, 0, 0);public static Color Green = new Color(0, 255, 0);public static Color Blue = new Color(0, 0, 255);private byte red, green, blue;
public Color(byte r, byte g, byte b) {red = r;green = g;blue = b;}}
public class Color{public static readonly Color Black = new Color(0, 0, 0);public static readonly Color White = new Color(255, 255, 255);public static readonly Color Red = new Color(255, 0, 0);public static readonly Color Green = new Color(0, 255, 0);public static readonly Color Blue = new Color(0, 0, 255);private byte red, green, blue;
public Color(byte r, byte g, byte b) {red = r;green = g;blue = b;}}