如何按对象的属性对列表进行排序

Tuy*_*ham 0 c# sorting list

如何List<ABC>c1元素排序?非常感谢你!

public class ABC
{
    public string c0 { get; set; }
    public string c1 { get; set; }
    public string c2 { get; set; }
}
public partial class MainWindow : Window
{
    public List<ABC> items = new List<ABC>();
    public MainWindow()
    {
        InitializeComponent();
        items.Add(new ABC
        {
            c0 = "1",
            c1 = "DGH",
            c2 = "yes"
        });
        items.Add(new ABC
        {
            c0 = "2",
            c1 = "ABC",
            c2 = "no"
        });
        items.Add(new ABC
        {
            c0 = "3",
            c1 = "XYZ",
            c2 = "yes"
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

Col*_*inE 5

这个怎么样:

var sortedItems = items.OrderBy(i => i.c1);
Run Code Online (Sandbox Code Playgroud)

IEnumerable<ABC>如果需要列表,则返回一个ToList:

List<ABC> sortedItems = items.OrderBy(i => i.c1).ToList();
Run Code Online (Sandbox Code Playgroud)