// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; class B { private A a; public B(A a) { this.a = a; // argument shadows for instance member } public void foobar() { Console.WriteLine(a.V); Console.WriteLine(a[77]); } } class A { private int v; private B b; public A(int v) { this.v = v; // argument shadows for instance member b = new B(this); // pass itself as argument } public A() : this(0) // use another constructor { } public int V { get { return v; } } public int this[int ix] // indexer { get { return v; } } public void foobar() { b.foobar(); } } class MainClass { public static void Main(string[] args) { A a1 = new A(123); a1.foobar(); A a2 = new A(); a2.foobar(); } }