i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List descending order using Linq C#
07-30-2012, 01:55 PM
Post: #1
List descending order using Linq C#
Using Linq, we can easily sort the List by descending order, here is the code for this
Code:
using System.Linq;// add namespace

List<int> deleteInfo = new List<int>();
deleteInfo.Add(1);
deleteInfo.Add(2);
deleteInfo.Add(4);
deleteInfo.Add(6);
deleteInfo.Add(7);
deleteInfo.Add(3);

            var IndexValue = from element in deleteInfo
                             orderby element descending
                             select element;

            foreach (int value in IndexValue)
                //use value to get the element




[Image: 2604595733.png]
Quote
08-02-2012, 08:20 AM
Post: #2
RE: List descending order using Linq C#
Thanks, will check that...



View Asad Ali's profile on LinkedIn

Quote
08-02-2012, 08:25 AM
Post: #3
RE: List descending order using Linq C#
or you can simply do this
List orderlist = deleteInfo.OrderBy((x) => x ).ToList();
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Can I Convert list = new List<...> from Net 4.0 to Net 2.0 ? dongtrien 0 2,010 09-29-2016 01:23 AM
Last Post: dongtrien
  Order number of datagridview ? dongtrien 0 790 11-30-2015 06:40 AM
Last Post: dongtrien
  Filter list items using linq c# nisar87 0 4,707 12-23-2012 05:23 PM
Last Post: nisar87
  Get distinct items form List<string> using Linq c# nisar87 0 2,389 12-23-2012 05:10 PM
Last Post: nisar87
  Sort the elements of the array in descending order Shafiur Rahman 3 5,605 10-03-2010 04:36 PM
Last Post: nisar87



User(s) browsing this thread: 1 Guest(s)