我有一个自定义对象的集合,如下所示:
public struct Record {
public string Caller { get; set; }
public DateTime Started { get; set; }
public string Dialed { get; set; }
public decimal Duration { get; set; }
public decimal Cost { get; set; }
public string Location { get; set; }
public Switch Switch { get; set; }
}
public static List<Record> Records { get; set; }
使用LINQ,如何使用Records
中存储的值按升序对Record.Started
进行排序?
答案 0 :(得分:2)
只需使用OrderBy
方法:
Records.OrderBy(record => record.Started)
或:
from r in Records
order by r.Started
select r
答案 1 :(得分:1)
难道这很容易吗?
records.OrderBy(r=>r.Started)