I have a class PropertyDetails
:
public class PropertyDetails
{
public int Sequence { get; set; }
public int Length { get; set; }
If you want to sort the existing list in-place then you can use the Sort method:
List propertyDetailsList = ...
propertyDetailsList.Sort((x, y) => x.Sequence.CompareTo(y.Sequence));
If you want to create a new, sorted copy of the list then you can use LINQ's OrderBy method:
List propertyDetailsList = ...
var sorted = propertyDetailsList.OrderBy(x => x.Sequence).ToList();
(And if you don't need the results as a concrete List
then you can omit the final ToList
call.)