コード例 #1
0
        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();
        }
コード例 #2
0
 public void AddAddress(Address address)
 {
     address.Parent = this;
     addresses.Add(address);
 }