Function returning the highest value in a table

advertisements

I am still having slight troubles with functions and arrays. I have created an array that has been filled with random numbers. I am trying to create a function that sets up the array and returns the highest value. I am not to sure on how to approach this but this and what I have written so far has not been able to compile.

namespace Task_1._13
{
    class Program
    {
        static void Main(string[] args)
        {
            gettingMaximum(int i);
        }

        public int gettingMaximum(int i);
        {
            int maximum = 0;
            int[] myArray = new int[10];
            Random rand = new Random();

            for (int i = 0; i < myArray.Length; i++)
            {
                myArray[i] = rand.Next(19);
            }
            for (int i = 0; i < 10; i++)
            {
                if (i == 0)
                    maximum = myArray[i];
                else
                    if (myArray[i] < maximum) maximum = myArray[i];
                int result = i;
                return result;
            }
        }
    }
}

That's what I have gotten so far. I am not very experienced in programming so help would be appreciated.


for (int i = 0; i < myArray.Length; i++)
        {
            if(myArray[i] > maximum)
           {
             maximum = myArray[i];
           }
        }
return maximum;

OR you can just use the Max function like this

return myArray.Max();