// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; namespace E { public struct S { public int A; public int B; public int C; public S(int a, int b, int c) { A = a; B = b; C = c; } public override string ToString() { return string.Format("({0},{1},{2})", A, B, C); } } public class Program { private static S s = new S(1, 2, 3); public static ref readonly S M() { return ref s; } public static void Main(string[] args) { ref readonly S s = ref M(); // not allowed: // s.A = 321; Console.WriteLine(s); } } }