# Why do I need an array in a method, and what should I do if I don't throw an exception when entering data into the array?

+2 votes
``using System;namespace ConsoleApp1{    class Program    {        static void Main(string[] args)        {                                    void Func(int[] numbers,int L, int R)            {                int  middle, I, J, F, Z;                                I = L; J = R;                middle = (L + R) / 2;                do                {                    do                    {                        F = 0;                        if (numbers[I] < numbers[middle]) F = -1;                        if (numbers[I] > numbers[middle]) F = 1;                        if (F > 0) I = I + 1;                        Console.WriteLine(I);                    }                    while                    (F < 0);                    do                    {                        F = 0;                        if (numbers[J] < numbers[middle]) F = -1;                        if (numbers[J] > numbers[middle]) F = 1;                        if (F > 0) J = J + 1;                        Console.WriteLine(J);                    }                    while                    (F < 0);                    if  (I <= J)                    {                         Z = numbers[I]; numbers[I] = numbers[J]; numbers[J] = Z;                    }                }                while                (I <= J);                if (L < J) Func(numbers, L, J);                 else if (I < R) Func(numbers, I, R);            }            Func(numbers,15, 10);        }    }}``
Why do we need an array in this method, what role does it play and how to bypass an exception without handling it is a silly question, but the code was written from an algorithmic language and I'm sure there is no such thing in terms of error handling

## 1 Answer

0 votes
by

Best answer
You saved the code incorrectly, apparently. You have func nested in main. First of all, and secondly, why - it's a quick sort, and yes, in order to sort the array, you have to pass it to it. And entering data into the array is not present in your code at the moment.