c# sorting code example
Example 1: built in methods to order a list c#
using System.Linq;
List<Order> objListOrder = new List<Order>();
List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
List<Order> SortedList = objListOrder.OrderByDescending(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: array sort c#
Array.Sort(myArray);
Example 4: c# sort array
Array.Sort(arr);
Example 5: c# sort array
int[] sortedCopy = from element in copyArray
orderby element ascending select element;
Example 6: sorting array in c#
int[] arr = { 3, 6, 4, 1 };
Array.Sort(arr);
Array.Sort(arr);
Array.Reverse(arr);