SoFunction
Updated on 2025-03-06

c# Get the value of the largest number in the array

Find the value of the largest number in the array:
1. The max function of the array:

Copy the codeThe code is as follows:

class Program
    {
        static void Main(string[] args)
        {
            int[] array = {1,3,5,2,4,6,7,9,0,8};
           int max= GetMax(array);
("The largest value in the array is {0}",max);
            ();
        }
        /// <summary>
/// The largest value in the array
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        private static int GetMax(int[] array)
        {
          return ();
        }
    }

2. Branch statement:

Copy the codeThe code is as follows:

class Program
    {
        static void Main(string[] args)
        {
            int[] array = {1,3,5,2,4,6,7,9,0,8};
           int max= GetMax(array);
("The largest value in the array is {0}",max);
            ();
        }
        /// <summary>
/// The largest value in the array
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        private static int GetMax(int[] array)
        {
            int max = 0;
            for (int i = 0; i <; i++)
            {
                max = max > array[i] ? max : array[i];

            }
            return max;
        }
    }

3. Triple operation:

Copy the codeThe code is as follows:

class Program
    {
        static void Main(string[] args)
        {
            int[] array = {1,3,5,2,4,6,7,9,0,8};
           int max= GetMax(array);
("The largest value in the array is {0}",max);
            ();
        }
        /// <summary>
/// The largest value in the array
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        private static int GetMax(int[] array)
        {
            int max = 0;
            for (int i = 0; i <; i++)
            {
                max = max > array[i] ? max : array[i];

            }
            return max;
        }
    }