public static void Main()
        {
            BiDictionary <string, string, Student> students = new BiDictionary <string, string, Student>();
            List <string> firstKeysTest  = new List <string>();
            List <string> secondKeysTest = new List <string>();
            List <string> bothKeysTest   = new List <string>();
            Random        random         = new Random();

            for (int i = 0; i < 10; i++)
            {
                var     lengthFirstName = random.Next(2, 20);
                string  firstName       = GetRandomString(lengthFirstName, random);
                var     lengthLastName  = random.Next(2, 20);
                string  lastName        = GetRandomString(lengthLastName, random);
                Student student1        = new Student(firstName, lastName);
                students.Add(student1.FirstName, student1.LastName, student1);
                firstKeysTest.Add(student1.FirstName);
                secondKeysTest.Add(student1.LastName);
                bothKeysTest.Add(student1.FirstName + student1.LastName);
                if (i % 2 == 0)
                {
                    Student student2 = new Student(firstName, lastName);
                    students.Add(student2.FirstName, student2.LastName, student2);
                    firstKeysTest.Add(student2.FirstName);
                    secondKeysTest.Add(student2.LastName);
                    bothKeysTest.Add(student2.FirstName + student2.LastName);
                }
            }

            for (int i = 0; i < 10; i++)
            {
                var searchedFirstNameIndex = random.Next(0, firstKeysTest.Count);
                var studentsByFirstName    = students.FindByFirstKey(firstKeysTest[searchedFirstNameIndex]);
                Console.WriteLine("New Search");
                Console.WriteLine("Students searched by first name:");
                foreach (var st in studentsByFirstName)
                {
                    Console.WriteLine("Student:" + st.FirstName + " " + st.LastName);
                }

                var searchedLastNameIndex = random.Next(0, secondKeysTest.Count);
                var studentsByLastName    = students.FindBySecondKey(secondKeysTest[searchedLastNameIndex]);
                Console.WriteLine("Students searched by last name:");
                foreach (var st in studentsByLastName)
                {
                    Console.WriteLine("Student:" + st.FirstName + " " + st.LastName);
                }

                var studentsByBothNames = students.FindByBothKeys(firstKeysTest[i], secondKeysTest[i]);
                Console.WriteLine("Students searched by both names:");
                foreach (var st in studentsByBothNames)
                {
                    Console.WriteLine("Student: " + st.FirstName + " " + st.LastName);
                }

                Console.WriteLine();
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            // Demo
            BiDictionary <string, string, string> people = new BiDictionary <string, string, string>();

            people.Add("Ivan", "Ivanov", "Front-Ender");
            people.Add("Ivan", "Ivanov", ".NET Ninja");
            people.Add("Ivan", "Georgiev", "Web Developer");
            people.Add("Ivan", "Georgiev", "Student");
            people.Add("Georgi", "Ivanov", "Driver");
            people.Add("Georgi", "Georgiev", "Lawyer");

            var jobsOfPeopleWithFirstNameIvan      = people.FindByFirstKey("Ivan");
            var jobsOfPeopleWithFirstNameGeorgi    = people.FindByFirstKey("Georgi");
            var jobsOfPeopleWithSecondNameIvanov   = people.FindBySecondKey("Ivanov");
            var jobsOfPeopleWithSecondNameGeorgiev = people.FindBySecondKey("Georgiev");
            var jobsOfPeopleWithNameIvanIvanov     = people.FindByBothKeys("Ivan", "Ivanov");

            Console.WriteLine("The jobs of the people with first name Ivan");
            foreach (var job in jobsOfPeopleWithFirstNameIvan)
            {
                Console.WriteLine(job);
            }

            Console.WriteLine("\nThe jobs of the people with first name Georgi");
            foreach (var job in jobsOfPeopleWithFirstNameGeorgi)
            {
                Console.WriteLine(job);
            }

            Console.WriteLine("\nThe jobs of the people with second name Ivanov");
            foreach (var job in jobsOfPeopleWithSecondNameIvanov)
            {
                Console.WriteLine(job);
            }

            Console.WriteLine("\nThe jobs of the people with second name Georgiev");
            foreach (var job in jobsOfPeopleWithSecondNameGeorgiev)
            {
                Console.WriteLine(job);
            }

            Console.WriteLine("\nThe jobs of the people with full name Ivan Ivanov");
            foreach (var job in jobsOfPeopleWithNameIvanIvanov)
            {
                Console.WriteLine(job);
            }
        }
예제 #3
0
        public static void Main()
        {
            BiDictionary <string, string, int> persons = new BiDictionary <string, string, int>();

            persons.Add("Nikolay", "Petrov", 21);
            persons.Add("Doncho", "Minkov", 25);
            persons.Add("Ivaylo", "Kenov", 25);
            persons.Add("Nikolay", "Kostov", 23);

            int[] ages = persons.FindByFirstKey("Nikolay");
            Console.WriteLine(string.Join(", ", ages));

            ages = persons.FindBySecondKey("Kenov");
            Console.WriteLine(string.Join(", ", ages));

            ages = persons.FindByBothKeys("Nikolay", "Petrov");
            Console.WriteLine(string.Join(", ", ages));
        }