static void Main(string[] args) { int[] newArr = { 1, 2, 3 }; int[] newArr1 = new int[15]; DynamicArray <int> array = new DynamicArray <int>(5); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter initialization with constructor"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); array.AddRange(newArr); Console.WriteLine(); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine($"\nAfter AddRange(newArr), newArr.Length = {newArr.Length};"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); array.Add(-1); Console.WriteLine(); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter adding to the end \'-1\'"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); array.Insert(-4, 2); Console.WriteLine(); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter adding \'-4\' at position 2"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); array.Insert(-4, 6); Console.WriteLine(); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter adding \'-4\' at position 6"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); if (array.Remove(-40)) { Console.WriteLine(); for (int i = 0; i < array.Capacity; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter remove \'-40\'"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); } if (array.Remove(-4)) { Console.WriteLine(); for (int i = 0; i < array.Length; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter remove \'-4\'"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); } array.AddRange(newArr1); Console.WriteLine(); for (int i = 0; i < array.Length; ++i) { Console.Write(array[i] + " "); } Console.WriteLine("\nAfter adding big array"); Console.WriteLine($"\nCapacity equals to {array.Capacity}"); Console.WriteLine($"Length equals to {array.Length}"); Console.ReadKey(); }
static void Main(string[] args) { DynamicArray <int> dynamicArray = new DynamicArray <int>(5); DynamicArray <char> dynamicArrayChar = new DynamicArray <char>(5); dynamicArray.Add(1); dynamicArray.Add(4); dynamicArray[2] = 5; dynamicArray[3] = 333; dynamicArray.Add(1); Console.WriteLine("{0},{1}", dynamicArray.Capacity, dynamicArray.Length); dynamicArray.AddRange(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); Console.WriteLine("{0},{1}", dynamicArray.Capacity, dynamicArray.Length); for (int i = 0; i < dynamicArray.Length; i++) { Console.WriteLine(dynamicArray[i]); } dynamicArray.Remove(1); dynamicArray.Sort(); Console.WriteLine(); for (int i = 0; i < dynamicArray.Length; i++) { Console.WriteLine(dynamicArray[i]); } foreach (int j in dynamicArray) { Console.WriteLine(j + "!!"); } //Console.WriteLine("{0},{1}", dynamicArray.Capacity, dynamicArray.Length); //dynamicArray.Remove(3); //for (int i = 0; i < dynamicArray.Length; i++) //{ // Console.WriteLine(dynamicArray[i]); //} //Console.WriteLine("{0},{1}", dynamicArray.Capacity, dynamicArray.Length); //dynamicArray.Insert(4, 55555); //for (int i = 0; i < dynamicArray.Length; i++) //{ // Console.WriteLine(dynamicArray[i]); //} //Console.WriteLine("{0},{1}", dynamicArray.Capacity, dynamicArray.Length); //dynamicArrayChar.Add('п'); //dynamicArrayChar.Add('р'); //dynamicArrayChar[2] = 'и'; //dynamicArrayChar[3] = 'в'; //dynamicArrayChar.Add('е'); //dynamicArrayChar.AddRange(new[] { 'т', ' ', 'д', 'р', 'у', 'г', '!' }); //for (int i = 0; i < dynamicArrayChar.Length; i++) //{ // Console.Write(dynamicArrayChar[i]); //} //dynamicArrayChar.Remove('п'); //for (int i = 0; i < dynamicArrayChar.Length; i++) //{ // Console.Write(dynamicArrayChar[i]); //} //Console.WriteLine("{0},{1}", dynamicArrayChar.Capacity, dynamicArrayChar.Length); //dynamicArrayChar.Remove(4); //for (int i = 0; i < dynamicArrayChar.Length; i++) //{ // Console.Write(dynamicArrayChar[i]); //} //Console.WriteLine("{0},{1}", dynamicArrayChar.Capacity, dynamicArrayChar.Length); //dynamicArrayChar.Insert(4, '!'); //for (int i = 0; i < dynamicArrayChar.Length; i++) //{ // Console.Write(dynamicArrayChar[i]); //} //Console.WriteLine("{0},{1}", dynamicArrayChar.Capacity, dynamicArrayChar.Length); Console.ReadLine(); }