假设我有一个名为 Person 的类:
public class Person
{
public int Age { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
以及人员名单:
Person { Age = 20, FirstName = "John", LastName = "Joe" }
Person { Age = 20, FirstName = "John", LastName = "Joe" }
Person { Age = 10, FirstName = "James", LastName = "Dokes" }
我想要的是一个(新的或旧的具有新属性的)列表,该列表按年龄、名字和姓氏对人进行分组,并且我还想知道该对象被分组了多少次。
所以上面的结果是:
Person { Age = 20, FirstName = "John", LastName = "Joe", Count = 2 }
Person { Age = 10, FirstName = "James", LastName = "Dokes", Count = 1 }