Return the position of the maximum in the list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Return the position of the maximum in the list.

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*from www.  j ava  2 s .c  o m*/

public class Main{
        /// <summary>
        /// Return the position of the maximum in the list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static int PosofMaximum(IList<int> list)
        {
            int index = 0;
            int max = list[0];
            for (int i = 1; i < list.Count; i++)
            {
                if (list[i] > max)
                {
                    max = list[i];
                    index = i;
                }
            }
            return index;
        }
}

Related Tutorials