Пример #1
0
        static void Main(string[] args)
        {
            // Пример использования.
            var    dict            = new CompositeKeyDictionary <Person, Address, House>();
            var    ind             = 1;
            var    addressToSelect = new Address($"Country_{ind}", $"City{ind}", $"Street_{ind}", ind);
            Person personToSelect;

            FillDictionary(dict, out personToSelect);

            Console.WriteLine("All items:");
            foreach (var item in dict)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Console.WriteLine($"Selected by address: {addressToSelect}");
            foreach (var item in dict.GetValuesByKey2(addressToSelect))
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Console.WriteLine($"Selected by person: {personToSelect}");
            foreach (var item in dict.GetValuesByKey1(personToSelect))
            {
                Console.WriteLine(item.ToString());
            }

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Пример использования. 
            var dict = new CompositeKeyDictionary<Person, Address, House>();
            var ind = 1;
            var addressToSelect = new Address($"Country_{ind}", $"City{ind}", $"Street_{ind}", ind);
            Person personToSelect;

            FillDictionary(dict, out personToSelect);

            Console.WriteLine("All items:");
            foreach (var item in dict)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();
           
            Console.WriteLine($"Selected by address: {addressToSelect}");
            foreach (var item in dict.GetValuesByKey2(addressToSelect))
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine();

            Console.WriteLine($"Selected by person: {personToSelect}");
            foreach (var item in dict.GetValuesByKey1(personToSelect))
            {
                Console.WriteLine(item.ToString());
            }

            Console.ReadLine();
        }
        public void GetValuesByKey1()
        {
            _dict.Add(_john, _firstAddr, _redHouse);
            _dict.Add(_john, _secondAddr, _blueHouse);
            _dict.Add(_bill, _thirdAddr, _greenHouse);
            _dict.Add(_bill, _fourthAddr, _blackHouse);

            var counter = 0;

            foreach (var item in _dict.GetValuesByKey1(_john))
            {
                counter++;
                Assert.IsTrue(item.Equals(_redHouse) ||
                              item.Equals(_blueHouse));
            }
            Assert.IsTrue(counter == 2);
        }