static void Main(string[] args) { DynamicArray <int> arr = new DynamicArray <int>(1); arr.Add(1); arr.Add(2); arr.PrintArray(); int[] number = new int[] { 1, 2, 3, 4, 5, 12 }; arr.AddRange(number); arr.PrintArray(); if (arr.Remove(6)) { Console.WriteLine("Элемент удален"); } else { Console.WriteLine("Элемент не удален"); } arr.PrintArray(); try { arr.Insert(8, 5); arr.PrintArray(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Третий элемент массива: " + arr[2]); Console.ReadLine(); }
static void Main() { /*int[] arr = new int[] { 1, 2 }; * DynamicArray<int> darr = new DynamicArray<int>(arr); * int n = darr.Length; * * DynamicArray<int> darr1 = new DynamicArray<int>(); * * int c = darr1.Capacity; * * int[] arr1 = new int[3]; * var d = arr1[0]; * // var e = arr1[9]; * arr1[2] = 4; * //arr1[10] = 6; * * int?[] arr2 = new int?[3]; * int f = arr2.Length; * * int j = 0; * for (int i=0; i< arr2.Length; i++) * { * if (arr2[i] != null) * j++; * }*/ DynamicArray <int> dinar = new DynamicArray <int>(3); Console.WriteLine(); Console.WriteLine(dinar.Length); Console.WriteLine(dinar.Capacity); dinar.Add(6); Console.WriteLine(); Console.WriteLine(dinar.Length); Console.WriteLine(dinar.Capacity); int[] arr = new int[] { 1, 2, 3, 4, 5 }; dinar.AddRange(arr); Console.WriteLine(); Console.WriteLine(dinar.Length); Console.WriteLine(dinar.Capacity); Console.WriteLine(); dinar.PrintArray(); dinar.Remove(4); Console.WriteLine(); Console.WriteLine(dinar.Length); Console.WriteLine(dinar.Capacity); Console.ReadKey(); }