LINQ - 使用类型计数对对象进行分组
我有一个对象集合,每个对象都由特定的“组”定义。如何编写 LINQ 查询来生成按“组”分组的每个对象的计数。
举个例子,假设我有以下课程;
public class Release
{
int ReleaseNumber;
public ReleaseDetails[] details;
}
public class ReleaseDetails
{
string Group;
// other details omitted
}
对于给定的版本,我希望能够产生如下输出:
Release number 1 contains the following details;
- 17 records in Group A
- 12 records in Group B
- 6 records in Group C
非常感谢任何帮助。
I have a collection of objects that each defined by a particular "group". How can I write a LINQ query to produce a count of each object grouped by "group".
As an example, lets say I have the following classes;
public class Release
{
int ReleaseNumber;
public ReleaseDetails[] details;
}
public class ReleaseDetails
{
string Group;
// other details omitted
}
For a given release, I'd like to be able to produce output like;
Release number 1 contains the following details;
- 17 records in Group A
- 12 records in Group B
- 6 records in Group C
Any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行类似
完整示例的操作:
You can do something like
Full example:
干得好。
Here you go.