コード例 #1
0
        public void Start()
        {
            Dictionary <PersonKey, Person> storage = new Dictionary <PersonKey, Person>();

            Person p = new Person {
                Age = 33, Name = "Jason", Address = null
            };
            PersonKey key = new PersonKey(p);

            Person p1 = new Person {
                Age = 35, Name = "Rob", Address = null
            };
            PersonKey key1 = new PersonKey(p1);

            storage[key]  = p;
            storage[key1] = p1;

            var searchKey  = new PersonKey(33, "Jason");
            var searchKey2 = new PersonKey(33, "Jason1");

            try {
                Console.WriteLine($"Key-{Key(key)}, Data-{storage[key]}");             //<-- Jason person
                Console.WriteLine($"Key-{Key(searchKey)}, Data-{storage[searchKey]}"); //<-- Jason person

                if (storage.ContainsKey(searchKey2))                                   // not found
                {
                    Console.WriteLine($"<{storage[searchKey2]}>");
                }
                else
                {
                    Console.WriteLine("Not found searchKey2 key");
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
 private string Key(PersonKey key)
 {
     return($"<Age{key.Age},Name:{key.Name}>");
 }
コード例 #3
0
 public bool Equals(PersonKey k)
 {
     return(k != null && k.Age == this.Age && k.Name == this.Name);
 }