c# sorted list code example
Example 1: list sort c#
List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
Example 2: list sorting c#
using System.Linq;
myList.Sort();
myList.Sort();
myList.Reverse();
public int CompareTo(MyClass other)
{
return this.totalScore.CompareTo(other.varInClass)
}
Example 3: C# order a sorted list by key
SortedList<string,bool> l = new SortedList<string, bool>();
l.Add("a", true);
l.Add("b", false);
l.Add("c", true);
l.Add("d", false);
var orderByVal = l.OrderBy(kvp => kvp.Key);
Example 4: c# sort list
using System;
class Program
{
static void Main()
{
string[] colors = new string[]
{
"orange",
"blue",
"yellow",
"aqua",
"red"
};
Array.Sort(colors);
foreach (string color in colors)
{
Console.WriteLine(color);
}
}
}