Maximums the specified list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Maximums the specified list.

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;/*from  ww  w.  ja  v  a  2 s. c  om*/

public class Main{
        /// <summary>
        /// Maximums the specified list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static int Maximum(IEnumerable<int> list)
        {
            int max = int.MinValue;
            foreach (int num in list)
            {
                if (max < num)
                {
                    max = num;
                }
            }
            return max;
        }
        /// <summary>
        /// Looks for the maximum length of the ArrayList
        /// </summary>
        /// <param name="list">list of lists</param>
        /// <returns>the maximum length</returns>
        public static int Maximum(ArrayList list)
        {
            int max = 0;
            foreach (ICollection sublist in list)
            {
                if (max < sublist.Count)
                {
                    max = sublist.Count;
                }
            }
            return max;
        }
}

Related Tutorials