示例#1
0
        static void Main(string[] args)
        {
            var myArr = new MyArrayList <string>();

            myArr.Add("1");
            myArr.Add("2");
            myArr.Add("3");
            myArr.Add("4");
            myArr.Add("5");
            myArr.Add("4");
            myArr.Add("3");
            myArr.Add("2");
            myArr.Add("1");
            Array.ForEach(myArr.arrayList, Console.Write);
            Console.WriteLine();

            myArr.Remove(3);
            Array.ForEach(myArr.arrayList, Console.Write);
            Console.WriteLine();

            myArr.Remove("1");
            Array.ForEach(myArr.arrayList, Console.Write);
            Console.WriteLine();

            Console.WriteLine(myArr.IndexOf("5"));
            Console.WriteLine();

            Array.ForEach(myArr.Get("3"), Console.Write);
            Console.WriteLine();

            Console.WriteLine(myArr.Get(3));

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var list = new MyArrayList <int>(1);

            list.Add(1);
            list.Insert(0, 2);
            list.Insert(1, 5);
            Console.WriteLine($"Исходный список: {list}, размер списка = {list.Count}");

            var index = 1;

            Console.WriteLine($"Элемент по индексу {index} = {list[index]}");

            list[index] = 10;
            Console.WriteLine($"Заменен элемент по индексу {index}: {list}");

            var item = 50;

            Console.WriteLine($"Список содержит число {item}? {list.Contains(item)}");

            var removingItem = 2;

            Console.WriteLine($"Элемент {removingItem} удален из списка? {list.Remove(2)}");
            Console.WriteLine($"Список: {list}");

            var array = new int[list.Count];

            list.CopyTo(array, 0);
            Console.WriteLine("Массив = " + string.Join(", ", array));
        }
示例#3
0
        static void Main(string[] args)
        {
            MyArrayList list = new MyArrayList();

            list.Add(1);
            list.Add("hello");
            list.Add(false);
            Console.WriteLine(list[0]);
            Console.WriteLine(list[1]);
            Console.WriteLine(list[2]);
        }
示例#4
0
 public MyArrayList(MyArrayList <T> array)
 {
     if (array.Capacity < 1)
     {
         throw new ArgumentException("Input array is empty");
     }
     this.Capacity   = array.Capacity;
     this.LowerBound = array.LowerBound;
     this.array      = new T[this.Capacity];
     array.CopyTo(this);
 }
示例#5
0
        public void CopyTo(MyArrayList <T> array)
        {
            if (array.Capacity < this.Capacity)
            {
                throw new ArgumentException("Capacity of target array must be greater or equal to this array");
            }

            for (int i = 0, k = array.LowerBound; i < this.Capacity; i++, k++)
            {
                array[k] = this.array[i];
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            MyArrayList <int> numeros = new MyArrayList <int>();

            numeros.add(5);
            numeros.add(15);
            numeros.add(89);
            numeros.add(24);
            numeros.add(789);
            numeros.add(963);
            numeros.add(856);
            numeros.add(753);
            numeros.add(7985);

            Console.WriteLine(numeros.get(0));
            Console.WriteLine(numeros.get(1));
            Console.WriteLine(numeros.get(2));
            Console.WriteLine(numeros.get(6));
            Console.WriteLine(numeros.get(7));
            Console.WriteLine(numeros.get(8));
        }