Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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