Returns a portion of the list whose keys are less than the limit object parameter. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Returns a portion of the list whose keys are less than the limit object parameter.

Demo Code


using System.IO;/*from w  w  w . ja va 2 s  . c o m*/
using System;

public class Main{
        /// <summary>
        /// Returns a portion of the list whose keys are less than the limit object parameter.
        /// </summary>
        /// <param name="l">The list where the portion will be extracted.</param>
        /// <param name="limit">The end element of the portion to extract.</param>
        /// <returns>The portion of the collection whose elements are less than the limit object parameter.</returns>
        public static System.Collections.SortedList HeadMap(System.Collections.SortedList l, Object limit)
        {
            System.Collections.Comparer comparer = System.Collections.Comparer.Default;
            System.Collections.SortedList newList = new System.Collections.SortedList();

            for (int i = 0; i < l.Count; i++)
            {
                if (comparer.Compare(l.GetKey(i), limit) >= 0)
                    break;

                newList.Add(l.GetKey(i), l[l.GetKey(i)]);
            }

            return newList;
        }
}

Related Tutorials