static void Main(string[] args) { Person p = new Person() { Name = "Adam Greene" }; var addr1 = new Address() { Street = "100 Main St" }; var addr2 = new Address() { Street = "200 Left St" }; var addr3 = new Address() { Street = "300 Right St" }; p.Addresses.Add(addr1); p.Addresses.Add(addr2); p.MainAddress = addr3; // Show that parent is automatically set Console.WriteLine("Parent Name: {0}", addr1.Parent.Name); //VisitChildren(p); ((IDisposable)p).Dispose(); }
public void AddAddress(Address address) { address.Parent = this; addresses.Add(address); }