示例#1
0
        static void Main(string[] args)
        {
            DynamicList <int> dl = new DynamicList <int>();

            for (int i = 0; i < 25; i++)
            {
                dl.Add(i);
            }
            for (int i = 0; i < dl.Count; i++)
            {
                Console.WriteLine(dl[i]);
            }
            Console.WriteLine("////////////////////////////");
            dl.Remove(10, 10);
            for (int i = 0; i < dl.Count; i++)
            {
                Console.WriteLine(dl[i]);
            }
            Console.WriteLine("////////////////////////////");
            dl.RemoveAt(10);
            for (int i = 0; i < dl.Count; i++)
            {
                Console.WriteLine(dl[i]);
            }
            Console.WriteLine("////////////////////////////");
            dl.RemoveAt(20);
            for (int i = 0; i < dl.Count; i++)
            {
                Console.WriteLine(dl[i]);
            }
            Console.WriteLine("////////////////////////////");
            dl.Clear();
            for (int i = 0; i < dl.Count; i++)
            {
                Console.WriteLine(dl[i]);
            }
            Console.WriteLine("////////////////////////////");
            //Console.WriteLine(dl.Count);
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            DynamicList <string> ArrStr = new DynamicList <string>();
            bool IsEnd = false;

            do
            {
                Console.WriteLine("\nНажмите 1, чтобы добавить элемент;\n" +
                                  "Нажмите 2, чтобы удалить элемент с конца;\n" +
                                  "Нажмите 3, чтобы удалить определенный элемент;\n" +
                                  "Нажмите 4, чтобы вывести количество элементовм;\n" +
                                  "Нажмите 5, чтобы заменить определенный элемент;\n" +
                                  "Нажмите 6, для очистки массива;\n" +
                                  "Нажмите 7, чтобы вывести весь массив;\n" +
                                  "Нажмите 8, чтобы выйти.\n");
                string Choice = Console.ReadLine();
                switch (Choice)
                {
                case "1":
                    Console.WriteLine("Введите элемент");
                    string addStr = Console.ReadLine();
                    ArrStr.Add(addStr);
                    break;

                case "2":
                    ArrStr.Remove();
                    break;

                case "3":
                    int index;
                    Console.WriteLine("Введите индекс элемента");
                    if (int.TryParse(Console.ReadLine(), out index))
                    {
                        ArrStr.RemoveAt(index);
                    }
                    break;

                case "4":
                    Console.WriteLine("Количество = " + ArrStr.count);
                    break;

                case "5":
                    string elem;
                    Console.WriteLine("Введите индекс и новый элемент");
                    if (int.TryParse(Console.ReadLine(), out index))
                    {
                        elem          = Console.ReadLine();
                        ArrStr[index] = elem;
                    }
                    break;

                case "6":
                    ArrStr.Clear();
                    Console.WriteLine("Массив очищен");
                    break;

                case "7":
                    Console.WriteLine("Ваш массив");
                    foreach (string i in ArrStr)
                    {
                        Console.WriteLine(i);
                    }
                    break;

                case "8":
                    IsEnd = true;
                    break;
                }
            } while (!IsEnd);
            Console.ReadKey();
        }