我有一个要使用 LINQ 查询的对象列表。我希望能够按属性对它们进行分组。
var query = from item in expense
orderby item.ExpenseTime descending
group item by item.Location;
var query = from item in expense
orderby item.ExpenseTime descending
group item by item.ExpenseType;
var query = from item in expense
orderby item.ExpenseTime descending
group item by item.Person;
有没有办法将属性指定为方法的参数?
public static void GetExpensesBy(List<Expense> expense, Property myGroupingProperty)
{
var query = from item in expense
orderby item.ExpenseTime descending
group item by item.myGroupingProperty;
// ....
}
请注意,查询后有通用代码,不关心组。