コード例 #1
0
        public static void TestContactInfo()
        {
            Phone p = new Phone();
            p.PhoneNum = 7551031;
            p.AreaCode = 801;

            ContactInfo c1 = new ContactInfo("*****@*****.**", new Address("007", "Bond City", "Utah", 84022, "no23778"),
                new Phone { AreaCode = 646, PhoneNum = 4351234 });

            //  Console.WriteLine(c1);

            ContactInfo johnContacntInfo = new ContactInfo("*****@*****.**", new Address("41 st", "NY", "NY", 10030, "24A"),
                new Phone { AreaCode = 654, PhoneNum = 8270061 });
            ContactInfo mariaContactInfo = new ContactInfo("*****@*****.**", new Address("77 st", "NY", "NY", 10030, "10A"),
              new Phone { AreaCode = 654, PhoneNum = 8270061 });

            Dictionary<string, ContactInfo> contacts = new Dictionary<string, ContactInfo>
            {
                ["John"] = johnContacntInfo,
                ["Maria"] = mariaContactInfo,
                ["Ben"] = new ContactInfo("*****@*****.**", new Address("5th Ave", "Seattle", "WA", 89125, "12B"),
                new Phone { AreaCode = 206, PhoneNum = 1234543 })
            };

            foreach (var entry in contacts)
            {
                Console.WriteLine(entry.Key);
                Console.WriteLine(entry.Value);
                Console.WriteLine();
                Console.WriteLine();

            }
        }
コード例 #2
0
 private static void TestDictionary()
 {
     ContactInfo johnContacntInfo = new ContactInfo("*****@*****.**", new Address("41 st", "NY", "NY", 10030, "24A"),
        new Phone { AreaCode = 654, PhoneNum = 8270061 });
     ContactInfo mariaContactInfo = new ContactInfo("*****@*****.**", new Address("77 st", "NY", "NY", 10030, "10A"),
       new Phone { AreaCode = 654, PhoneNum = 8270061 });
 }