Example #1
0
        private static void Main(string[] args)
        {
            var testArray1 = new DynamicArrayHardcoreMode <int>(new List <int> {
                1, 2, 3
            });

            testArray1.AddRange(new List <int> {
                4, 5, 6, 7
            });
            testArray1.Add(8);
            testArray1 = testArray1.Clone() as DynamicArrayHardcoreMode <int>;

            foreach (var item in testArray1)
            {
                Console.Write($"{item} ");
            }

            for (var i = -1; i >= -testArray1.Length; i--)
            {
                Console.WriteLine($"{i}) {testArray1[i]}");
            }

            Console.WriteLine($"{Environment.NewLine}Get ready and press any key");
            Console.ReadKey();

            var testArray2 = new CycledDynamicArray <int>(new List <int> {
                1, 2, 3, 4, 5
            });

            foreach (var item in testArray2)
            {
                Console.Write($"{item} ");
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("The application demonstrates a hardmode of dynamic array.");
            DynamicArrayHM <int> dynamicArrayHM = new DynamicArrayHM <int>(new int[] { 1, 2, 3, 4, 5 });

            Console.WriteLine("Using negative index(-3):");
            Console.WriteLine($"'-3' element is: {dynamicArrayHM[-3]}");
            Console.WriteLine("Dynamicly capacity changing:");
            dynamicArrayHM.SetCapacity(2);
            Console.WriteLine(dynamicArrayHM);
            dynamicArrayHM.SetCapacity(10);
            Console.WriteLine(dynamicArrayHM);
            CycledDynamicArray <int> cycledDynamicArray = new CycledDynamicArray <int>(new int[] { 1, 2, 3, 4, 5 });
            int counter = 0;

            Console.WriteLine("Endless array (limiter 1000):");
            foreach (var item in cycledDynamicArray)
            {
                counter++;
                Console.Write(item);
                if (counter == 1000)
                {
                    break;
                }
            }
            Console.WriteLine();
            Console.WriteLine("ReferenceEquals between dynamic array and its clone. They is equal:");
            Console.WriteLine(ReferenceEquals(dynamicArrayHM, dynamicArrayHM.Clone()));
        }
Example #3
0
        public static void Main(string[] args)
        {
            DynamicArrayHard <int> array = new DynamicArrayHard <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);
            array.Add(4);
            Console.WriteLine("Vice versa:");
            try
            {
                for (int i = -1; i >= -array.Length; i--)
                {
                    Console.Write(array[i]);
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            array.ChangeCapacity(5);
            Console.WriteLine("New capacity:");
            foreach (int item in array)
            {
                Console.Write(item);
            }

            Console.WriteLine();
            int[] newArray = array.ToArray();
            Console.WriteLine("To Array:");
            foreach (int item in newArray)
            {
                Console.Write(item);
            }

            Console.WriteLine();
            DynamicArray <int> arrayClone = new DynamicArray <int>(array.Length);

            arrayClone = (DynamicArray <int>)array.Clone();
            Console.WriteLine("Cloned Array:");
            foreach (var item in arrayClone)
            {
                Console.Write(item);
            }

            Console.WriteLine();
            CycledDynamicArray <int> arr = new CycledDynamicArray <int>();

            arr.Add(1);
            arr.Add(2);
            arr.Add(3);
            arr.Add(4);
            Console.WriteLine("Cycled Array:");
            foreach (var item in arr)
            {
                Console.Write(item);
            }

            Console.WriteLine();
        }