Search code examples
c#.netilist

Sorting IList<Specific_Object_Type>


Possible Duplicate:
Sorting an IList in C#

I have an IList<Keyword> where Keyword is a class containing a title(string) and a key(number). I wish to sort this IList based on the key. Is there an inbuilt C# functionality that I can use?


Solution

  • You need to add: using System.Linq;

    IList<keyword> sortedList = list.OrderBy(r => r.key).ToList();
    

    Or you can try:

      IList<keyword> sortedList2 = (from r in list
                                    orderby r.key
                                    select r).ToList();