+ Reply to Thread
Results 1 to 2 of 2

Thread: sort list

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    34

    sort list

    I have a record class :
    Code:
    public class DATA
    {
        public String ID;
        public String Name;
        public int Age;
    }
    And i have a list :
    Code:
    List<DATA> DATALIST = new List<DATA>();
    And i added records to the DATALIST but what i want is sorting the list base don the ID , name or Age.
    Any idea how can i do that ?

  2. #2
    You shouls use LINQ and that is the best option , so firstly use System.linq; , then use that code :
    Code:
    List<DATA> sorted = DATALIST.OrderBy(x => x.ID).ToList();
    OR
    List<DATA> sorted = DATALIST.OrderBy(x => x.Name).ToList();
    OR
    List<DATA> sorted = DATALIST.OrderBy(x => x.Age).ToList();
    Hope it was helpful.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts