Find Maximum Value in int array - CSharp System

CSharp examples for System:Array Find

Description

Find Maximum Value in int array

Demo Code


using System.Collections.Generic;
using System;/*from  w w  w .ja  va  2  s .c  om*/

public class Main{
        internal static int FindMaximumValue(params int[] elements)
        {
            if (elements == null || elements.Length == 0)
            {
                throw new ArgumentException("No elements to evaluate.");
            }

            var maximumValue = elements[0];
            for (int i = 1; i < elements.Length; i++)
            {
                if (maximumValue < elements[i])
                {
                    maximumValue = elements[i];
                }
            }

            return maximumValue;
        }
}

Related Tutorials