[ACCEPTED]-Is there a way of using orderby in a forloop C#?-sql-order-by

Accepted answer
Score: 35

Try this:

List<Item> myItems = new List<Item>();
//load myitems
foreach(Item i in myItems.OrderBy(t=>t.name))


Score: 2
new string[] { "d", "c", "b", "a" }
    .OrderBy(s => s)
    .ForEach(s => MessageBox.Show(s));


Score: 1

You don't need a Loop at all. Just use 1 LINQ:

List<MyClass> aList = new List<MyClass>();

// add data to aList

Score: 0

foreach needs an IEnumerable<T> LINQ order-by takes in one IEnumerable<T> and 2 gives you a sorted IEnumerable<T>. So yes, it should 1 work.

More Related questions