c# list sort by property string
var sortedQuery = sampleList.OrderBy(x => x.MyProperty);
c# list sort by property string
var sortedQuery = sampleList.OrderBy(x => x.MyProperty);
list sorting c#
using System.Linq;
//sorts in acending order {1,2,3,4,5}
myList.Sort();
//Sorts in decending order {5,4,3,2,1}
myList.Sort();
myList.Reverse();
//to sort a custom list of classes you have to
//add this inside of your class
public int CompareTo(MyClass other)//replace MyClass with your class type
{
//replace varInClass to the variable that you would like to compare
return this.totalScore.CompareTo(other.varInClass)
}
sorting a list of objects in c#
List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
List<Order> DescSortedList = objListOrder.OrderByDescending(o=>o.OrderDate).ToList();
c# list sort by property string
list.Sort((a, b) => a.StringProperty.CompareTo(b.StringProperty));
c# sort list
using System;
class Program
{
static void Main()
{
string[] colors = new string[]
{
"orange",
"blue",
"yellow",
"aqua",
"red"
};
// Call Array.Sort method.
Array.Sort(colors);
foreach (string color in colors)
{
Console.WriteLine(color);
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us