Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Const_V_Readonly
- {
- public const int I_CONST_VALUE = 2;
- public readonly int I_RO_VALUE;
- public Const_V_Readonly()
- {
- I_RO_VALUE = 3;
- }
- }
- public const int CM_IN_A_METER = 100;
- public readonly float PI = 3.14;
- 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 value
- I_RO_VALUE = new char[]{'V'}; //will cause compiler error
- }
- }
- 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
- }
- }
- var fi = this.GetType().BaseType.GetField("_someField", BindingFlags.Instance | BindingFlags.NonPublic);
- fi.SetValue(this, 1);
- 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; }
- }
- }
Add Comment
Please, Sign In to add comment