假设以下场景:
Public Class Store
Public Overridable Property Areas As List(Of Area)
End Class
Public Class Area
Public Overridable Property Shelves As List(Of Shelf)
End Class
Public Class Shelf
Public Property ID as integer
End Class
获取商店货架总数的最快方法是什么? IE。对于商店,我使用 Areas.Count 获取区域总数
或者我需要遍历每个区域并计算货架数量吗?
最佳答案
在 C# 中:
int count = Store.Areas.SelectMany(x => x.Shelves).Count();
转换为VB:
Dim count = Store.Areas.SelectMany(Function(x) x.Shelves).Count()
(使用 online converter ,而不是 VB 人员)
关于VB.NET LINQ - 集合内集合的计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030877/