Two maximal value in array. Sorted and Array.Sort() Compare the two methods of sorting the array in ascending order, where can I optimize? How best to handle exception handling?

    class Inside {

    Random rand = new Random();

        // step 1.1: Fill array, output array

        public void SortedArray(int arrSize) {

            int[] arrOne = new int[arrSize];
            Console.Write("Array size: " + arrSize + "\n\t\t\t\t\t\tARRAY\n");

            for (int x = 0; x &lt; arrOne.Length; x++) {

                arrOne[x] = rand.Next(-1000, 1000);
                Console.Write("{0, 8} | ", arrOne[x]);
                if (x % 8 == 0) Console.WriteLine();
            }

            // step 1.2: Sorted array and output on monitor two maximal value

            for (int i = 0; i &lt; arrOne.Length; i++) {

                int minIndex = i;
                for (int j = i + 1; j &lt; arrOne.Length; j++) if (arrOne[minIndex] &gt; arrOne[j]) minIndex = j;
                int temp = arrOne[minIndex];
                arrOne[minIndex] = arrOne[i];
                arrOne[i] = temp;
            }

            Console.Write("\n\n\t\t\t\t\t\tARRAY SORTED\n\n");

            for (int x = 0; x &lt; arrOne.Length; x++) {
                Console.Write("{0, 8} | ", arrOne[x]);
                if (x % 8 == 0) Console.WriteLine();
            }

            Console.WriteLine("\n\nMaximal value 1: " + arrOne[arrOne.Length - 1] + "\nMaximal value 2: " + arrOne[arrOne.Length - 2]);
        }

        // Step 2.1: Fill array and output

        public void SortedMethod(int arrSize) {

        int[] arrOne = new int[arrSize];
        Console.Write("Array size: " + arrSize + "\n\t\t\t\t\t\tARRAY\n");

        for (int x = 0; x &lt; arrOne.Length; x++)  {

            arrOne[x] = rand.Next(-1000, 1000);
            Console.Write("{0, 8} | ", arrOne[x]);
            if (x % 8 == 0) Console.WriteLine();
        }

        // Step 2.2: Sorted array and output on monitor two maximal value

        Array.Sort(arrOne);
        Console.Write("\n\n\t\t\t\t\t\tARRAY SORTED\n\n");

        for (int x = 0; x &lt; arrOne.Length; x++)  {
            Console.Write("{0, 8} | ", arrOne[x]);
            if (x % 8 == 0) Console.WriteLine();
        }
        Console.WriteLine("\n\nMaximal value 1: " + arrOne[arrOne.Length - 1] + "\nMaximal value 2: " + arrOne[arrOne.Length - 2]);
    }
}


// user class

class Data {

static void Main() {

        // Step 1: Call the sort method by selecting
        Inside obj = new Inside();
        Console.Write("Please, enter array size: ");
        int sizeArr = Convert.ToInt32(Console.ReadLine());
        var timeStart = Stopwatch.StartNew(); 
         obj.SortedArray(sizeArr);
         timeStart.Stop();

        // Step 2: Call method Array.sort()

        var timeStartTwo = Stopwatch.StartNew();
        obj.SortedMethod(sizeArr);
        timeStartTwo.Stop();

        // Step 3: Compare runtime

        Console.Write("SortedArray = {0}\nSortedMethod = {1}", timeStart.Elapsed, timeStartTwo.Elapsed + "\n");
    }
}
for (int j = i + 1; j &lt; arrOne.Length; j++) if (arrOne[minIndex] &gt; arrOne[j]) minIndex = j;



This is by far the worst line in your code. It took me a while to realize that there is actually an if behind the for while I was wondering why didn't you indent the three lines below it but wait, these lines are not part of the for, it's the if. You should always use curly brackets

for (int j = i + 1; j &lt; arrOne.Length; j++) 
{ 
    if (arrOne[minIndex] &gt; arrOne[j]) 
    {
        minIndex = j;
    }
}


This is how it should look like.