【发布时间】:2014-07-12 14:42:50
【问题描述】:
是否可以通过另一个列表对内存中的列表进行排序(第二个列表将是参考数据源或类似的东西)?
public class DataItem
{
public string Name { get; set; }
public string Path { get; set; }
}
// a list of Data Items, randomly sorted
List<DataItem> dataItems = GetDataItems();
// the sort order data source with the paths in the correct order
IEnumerable<string> sortOrder = new List<string> {
"A",
"A.A1",
"A.A2",
"A.B1"
};
// is there a way to tell linq to sort the in-memory list of objects
// by the sortOrder "data source"
dataItems = dataItems.OrderBy(p => p.Path == sortOrder).ToList();
【问题讨论】:
标签: c# asp.net linq linq-to-sql