Sorting a List of objects in C#

后端 未结 11 1884
终归单人心
终归单人心 2020-12-07 18:01
public class CarSpecs
{
  public String CarName { get; set; }

  public String CarMaker { get; set; }

  public DateTime CreationDate { get; set; }
}
11条回答
  •  时光取名叫无心
    2020-12-07 18:17

    To extend the answer of Noldorin, in order to sort a list with int datatype this can be used:

    listName.Sort((x, y) =>  x.CompareTo(y));
    

    Or if you have a complex object in the list:

    inventoryList.Sort((x, y) =>  x.stockNumber.CompareTo(y.stockNumber));
    

提交回复
热议问题