Exemple #1
0
        static void Main(string[] args)
        {
            HashTable <string> hashTable = new HashTable <string>(5);

            hashTable.Add("123");
            hashTable.Add("Николай Фомин");
            hashTable.Add("Золоторёв Александр");
            hashTable.Add("Анатолий Суслов");
            hashTable.Add("Николай Устинов");
            hashTable.Add("Анатолий Сахаров");
            hashTable.Add("Иванов Иван");
            hashTable.Add(null);

            Console.WriteLine(hashTable);
            Console.WriteLine("Count: {0}", hashTable.Count);

            Console.WriteLine("Contains(\"person1\"): {0}", hashTable.Contains("Иванов Иван"));
            Console.WriteLine("Contains(\"person2\"): {0}", hashTable.Contains("Иванов Иван12"));

            Console.WriteLine($"Remove(\"person1\"): {hashTable.Remove("Анатолий Суслов")}");

            Console.WriteLine(hashTable);

            hashTable.Clear();

            Console.WriteLine("Count: {0}", hashTable.Count);
            Console.WriteLine(hashTable);
        }
        static void Main()
        {
            HashTable <string> hash = new HashTable <string>(10);

            hash.Add("zero");
            hash.Add("one444");
            hash.Add(null);
            hash.Add(null);
            hash.Add("two");
            hash.Add("three");
            hash.Add("hello");
            hash.Add("four");

            foreach (var element in hash)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine();

            Console.WriteLine(hash.Contains("hello"));

            Console.WriteLine(hash.Remove("zero"));

            Console.WriteLine(hash.Contains(null));

            foreach (var element in hash)
            {
                Console.WriteLine(element);
            }

            string[] hashCopy = new string[hash.Count];

            hash.CopyTo(hashCopy, 0);

            Console.WriteLine("TEST");

            foreach (var item in hashCopy)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine(hash.Remove(null) + "test");

            foreach (var element in hash)
            {
                Console.WriteLine(element);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("--------------------------------Test Add Key Value Pairs-----------------------------");
            HashTable <string> MyHash = new HashTable <string>();

            MyHash.Add("Мастер и Маргарита");
            MyHash.Add("Преступление и наказание");
            MyHash.Add("Война и мир");
            MyHash.Add("Братья Карамазовы");
            MyHash.Add("Мёртвые души");
            MyHash.Add("Евгений Онегин");
            MyHash.Add("Граф Монте-Кристо");
            MyHash.Add("Отцы и дети");
            MyHash.Add("Воскресение");
            MyHash.Add("Анна Каренина");
            MyHash.Add("Золотой теленок");
            MyHash.Add("Капитанская дочка");
            MyHash.Add("Горе от ума");
            MyHash.Add("Обломов");
            MyHash.Add("Старик и море");
            MyHash.Add("Три мушкетера");

            //MyHash.Add(null);
            //MyHash.Add("Преступление и наказание");
            //MyHash.Add("Война и мир");
            //MyHash.Add("Братья Карамазовы");
            //MyHash.Add("Мёртвые души");
            //MyHash.Add("Евгений Онегин");
            //MyHash.Add("Граф Монте-Кристо");
            //MyHash.Add(null);
            //MyHash.Add("Воскресение");
            //MyHash.Add("Анна Каренина");
            //MyHash.Add(null);
            //MyHash.Add("Капитанская дочка");
            //MyHash.Add("Горе от ума");
            //MyHash.Add("Обломов");
            //MyHash.Add("Старик и море");
            //MyHash.Add("Три мушкетера");
            Console.Write(MyHash.ToString());

            Console.WriteLine();
            Console.WriteLine("-----------------------------------------Test Contains---------------------------------");
            string value1 = "Золотой теленок";

            Console.WriteLine("Value: {0} Result: {1}", value1, MyHash.Contains(value1));

            string value2 = "Три мушкетера";

            Console.WriteLine("Value: {0} Result: {1}", value2, MyHash.Contains(value2));

            string value3 = "Евгений Онегин";

            Console.WriteLine("Value: {0} Result: {1}", value3, MyHash.Contains(value3));

            string value4 = "Робинзон Крузо";

            Console.WriteLine("Value: {0} Result: {1}", value4, MyHash.Contains(value4));

            Console.WriteLine();
            Console.WriteLine("-----------------------------------------Test Remove------------------------------------");
            string value5 = "Золотой теленок";

            Console.WriteLine("Value: {0} Result: {1}", value5, MyHash.Remove(value5));
            Console.Write(MyHash.ToString());

            Console.WriteLine();
            string value6 = "Робинзон Крузо";

            Console.WriteLine("Value: {0} Result: {1}", value6, MyHash.Remove(value6));
            Console.Write(MyHash.ToString());

            Console.WriteLine();
            Console.WriteLine("-----------------------------------------Test CopyTo------------------------------------");
            string[] array = new string[20];
            MyHash.CopyTo(array, 2);

            foreach (string value in array)
            {
                Console.WriteLine((value == null) ? "null" : value);
            }

            Console.WriteLine();
            Console.WriteLine("--------------------------------Test Iterator-----------------------------");
            IEnumerator <string> iterator = MyHash.GetEnumerator();

            while (iterator.MoveNext())
            {
                Console.WriteLine("Value: {0}", iterator.Current);
            }

            Console.WriteLine();
            Console.WriteLine("-----------------------------------------Test Clear------------------------------------");
            MyHash.Clear();
            Console.Write(MyHash.ToString());

            Console.ReadKey();
        }