To Sorted Array By Value - CSharp System

CSharp examples for System:Array Sort

Description

To Sorted Array By Value

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, int>> ToSortedArrayByValue<TKey>(this Dictionary<TKey, int> list)
        {/*  w w w  .j  a  v  a  2  s . co  m*/
            List<KeyValuePair<TKey, int>> res = new List<KeyValuePair<TKey, int>>();

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

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


            return res;
        }
}

Related Tutorials