Пример #1
0
 // Function to clear the dictionary.
 public static void ClearDic(ref MyDictionary <int, AbstrState> myDictionary)
 {
     myDictionary.Clear();
     Console.WriteLine("The dictionary is clear now!\nPress ENTER to continue");
     Console.ReadLine();
 }
Пример #2
0
        // Clone the dictionary.
        public MyDictionary <K, T> Clone()
        {
            MyDictionary <K, T> buf = this;

            return(buf);
        }
Пример #3
0
        public static void Demonstrate()
        {
            Console.Clear();
            //Console.Write((int)'A' + " " + (int)'Z' + " " + (int)'a' + " " + (int)'z');

            // Getting the capacity from the user.
            int capacity = CapacityInput();

            // Creating a dictionary with the set capacity.
            MyDictionary <int, AbstrState> myDictionary = new MyDictionary <int, AbstrState>(capacity);

            Console.WriteLine("An empty dictionary with the capacity of {0} has been successfully created!\n", capacity);

            int choice;

            do
            {
                //Console.Clear();
                Console.WriteLine(@"Choose one of the options:
1. Fill the dictionary with random elements.
2. Show the dictionary.
3. Check if there is an element with the wanted key.
4. Check if there is an element with the wanted value.
5. Add an element.
6. Clear the dictionary.
7. Clone the dictionary.
8. Remove an element with the wanted value.
9. Back.");

                choice = Program.ChoiceInput(9);

                switch (choice)
                {
                case 1:
                    FillDic(ref myDictionary);
                    break;

                case 2:
                    ShowDic(myDictionary);
                    break;

                case 3:
                    CheckKey(myDictionary);
                    break;

                case 4:
                    CheckValue(myDictionary);
                    break;

                case 5:
                    AddElem(ref myDictionary);
                    break;

                case 6:
                    ClearDic(ref myDictionary);
                    break;

                case 7:
                    CloneDic(myDictionary);
                    break;

                case 8:
                    RemoveFromDic(ref myDictionary);
                    break;
                }

                Console.Clear();
            } while (choice != 9);
        }