简体   繁体   English

.NET 中子集合中的项目总数

[英]Total count of items in child collections in .NET

How to get count of items in the child collection ?如何获取子集合中的项目数?

class company
{
    public ObservableCollection<employee> employees { get; set; }
}

class employee
{
}

Lets say there are 5 companies and each company has 7 employees in its collection.假设有 5 家公司,每家公司都有 7 名员工。 How to get the count of total employees (=35)?如何获得员工总数(= 35)?

您可以使用SelectMany

Companies.SelectMany(x => x.employees).Count()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将项目分散到多个.NET集合中 - Spread items in multiple .NET collections Lambda计算列表中的项目总数 - Lambda to count total items in a list of lists 有没有办法使用LINQ合并重复项目的集合及其子集合? - Is there a way to merge a collection of duplicated items along with their child collections using LINQ? 如何在单个实体框架查询中返回许多子集合Count() - How to return many Child Collections Count() in a single entity framework query 在集合的多个实例中查找项目总数,并将其绑定到Textblock - Finding total number of items in multiple instances of a collection & binding count to Textblock 是否可以使用Linq获取列表列表中的项目总数? - Is it possible to use Linq to get a total count of items in a list of lists? 如何计算C#中特定父节点下的子节点总数? - How to count total child nodes under the specific parent in C#? 按百分比从ASP.NET集合中选择项目 - Select items from ASP.NET collections by percentage 使用JSON.NET将子数据集合反序列化为枚举数 - deserializing child data collections into ienumerables using JSON.NET 在ListView中绑定项目集合,但显示其子集合而不是主要项目本身 - Bind items collection in ListView, but show their child collections rather than the main items themselves
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM