Find Max Value in int array - CSharp System

CSharp examples for System:Array Find

Description

Find Max Value in int array

Demo Code

//     All rights reserved ? Telerik Academy 2012-2013
using System;/*from ww w . jav  a  2 s  . c o  m*/

public class Main{
        public static int FindMaxValue(params int[] elements)
        {
            if (elements == null)
            {
                throw new ArgumentNullException("Invalid sequence");
            }

            if (elements.Length == 0)
            {
                throw new ArgumentException("Sequence is empty.");
            }

            int maxValue = int.MinValue;
            for (int i = 1; i < elements.Length; i++)
            {
                if (elements[i] > maxValue)
                {
                    maxValue = elements[i];
                }
            }

            return maxValue;
        }
}

Related Tutorials