To Sorted Array By Key - CSharp System

CSharp examples for System:Array Sort

Description

To Sorted Array By Key

Demo Code


using System.Linq;
using System.Text;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;

public class Main{
        public static List<KeyValuePair<TKey, TValue>> ToSortedArrayByKey<TKey, TValue>(this Dictionary<TKey, TValue> list)
            where TKey : IComparable<TKey>
        {/*from   w  ww.  j a v  a2 s. c  om*/
            var res = new List<KeyValuePair<TKey, TValue>>();

            foreach (var valor in list)
            {
                res.Add(valor);
            }

            res.Sort((x, y) => x.Key.CompareTo(y.Key));


            return res;
        }
}

Related Tutorials