Get the Max Value in an array : int array « Data Type « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;

class Program {
    static int MaxValue(int[] intArray) {
        int maxVal = intArray[0];
        for (int i = 1; i < intArray.Length; i++) {
            if (intArray[i] > maxVal)
                maxVal = intArray[i];
        }
        return maxVal;
    }

    static void Main(string[] args) {
        int[] myArray = {
            1, 8, 3, 6, 2, 5, 9, 3, 0, 2
         };
        int maxVal = MaxValue(myArray);
        Console.WriteLine("The maximum value in myArray is {0}", maxVal);
    }
}








2.5.int array
2.5.1.int arrays
2.5.2.Initialize int arrays
2.5.3.Use a foreach loop through an int array
2.5.4.int array with for loop
2.5.5.Get the Max Value in an array