Skip to content

Instantly share code, notes, and snippets.

@controlflow
Created January 2, 2014 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save controlflow/8214142 to your computer and use it in GitHub Desktop.
Save controlflow/8214142 to your computer and use it in GitHub Desktop.
Value type + readonly field...
using System;
public struct S {
int _value;
public S(int value) { _value = value; }
public int Value { get { return _value; } }
public void Mutate() { _value++; }
}
public class C {
S _s = new S(42);
readonly S _r = new S(42);
public static void Main() {
var c = new C();
c._s.Mutate();
c._r.Mutate();
Console.WriteLine(c._s.Value); // 43
Console.WriteLine(c._r.Value); // 42
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment