我是相當新的通用編程,並有一個問題:通過特定屬性的通用訂購方法
我想按特定的屬性,應該定義爲參數排序列表。 請看代碼爲更好地瞭解我想要什麼:
public static IEnumerable<T> SortEmployeesFor<T>(
IEnumerable<T> list,
property1,
property2,
OrderOptions options)
{
switch (options)
{
case OrderOptions.1:
return list.OrderBy(x => property1).ThenBy(x => property2);
case OrderOptions.2:
return list.OrderBy(x => property2).ThenBy(x => x.property1);
...
}
return list;
}
是否有執行此的任何選項?
P.S.這是我的第一篇文章,如果我做錯了,請理解並讓我知道。
什麼property1和property2的類型? – Heisenbug