Beispiel #1
0
        static void Menu4()
        {
            int option = -1;

            while (option != 0)
            {
                Console.Clear();
                Console.WriteLine("1) Создать коллекцию.");
                Console.WriteLine("2) Вывести коллекцию.");
                Console.WriteLine("3) Удалить элемент.");
                Console.WriteLine("4) Добавить элемент.");
                Console.WriteLine("5) Вывести кол-во элементов.");
                Console.WriteLine("6) Найти элемент.");
                Console.WriteLine("7) Удалить коллекцию из памяти.");
                Console.WriteLine("0) Выход.");
                Console.WriteLine("Выберите опцию: ");
                option = Input.Int(0, 8);
                switch (option)
                {
                case 0:
                    return;

                    break;

                case 1:
                    Console.WriteLine("Введите размер коллекции: ");
                    int n = Input.Int(0, 10000000);
                    for (int i = 0; i < n; i++)
                    {
                        if (i == 0)
                        {
                            myCollection = new MyCollection <Country>(new Country());
                        }
                        else
                        {
                            myCollection.Add(new Country());
                        }
                    }
                    Console.WriteLine("Коллекция создана.");
                    break;

                case 2:
                    if (myCollection == null)
                    {
                        Console.WriteLine("Объект пуст.");
                    }
                    else
                    {
                        foreach (Country country in myCollection)
                        {
                            country.Print();
                        }
                    }
                    break;

                case 3:
                    Console.WriteLine("Введите элемент для удаления: ");
                    if (!MyCollection <Country> .Remove(ref myCollection, new Country()))
                    {
                        Console.WriteLine("Объект не найден");
                    }
                    else
                    {
                        Console.WriteLine("Объект удален");
                    }
                    break;

                case 4:
                    Console.WriteLine("Введите элемент для добавления: ");
                    myCollection.Add(new Country());
                    break;

                case 5:
                    Console.WriteLine("Кол-во элементов: " + myCollection.Count);
                    break;

                case 6:
                    Console.WriteLine("Введите элемент для поиска: ");
                    if (myCollection.Contains(new Country()) == -1)
                    {
                        Console.WriteLine("Элемент не найден");
                    }
                    else
                    {
                        Console.WriteLine("Элемент найден");
                    }
                    break;

                case 7:
                    myCollection.Dispose();
                    myCollection = null;
                    Console.WriteLine("Список удален из памяти");
                    break;
                }
                Console.ReadKey();
            }
        }
Beispiel #2
0
 public void Reset()
 {
     current  = this;
     position = -1;
 }