0
我有一個列表(StoreList)列表。我需要統計所有商店中所有可用的蘋果。不知道該怎麼做。從List(of myObject)列表中計數
Class myObject
Public What As String
Public Available As Boolean
End Class
Public Sub Test()
Dim ItemList As New List(Of myObject)
ItemList.Add(New myObject With {.What = "Apple", .Available = True})
ItemList.Add(New myObject With {.What = "Cherry", .Available = False})
Dim StoreList As New List(Of List(Of myObject))
StoreList.Add(ItemList)
'StoreList.Add(...)
'error here
Dim count As Integer = StoreList.Sum(_
ItemList.Where(Function(x As myObject) _
x.What = "Apple" And x.Available).Count)
End Sub
很明顯,我不能總結一個數字的方式,我正在做它。我如何使用Linq來計算所有商店中所有可用蘋果的數量?
@D_Bester - 此代碼爲我工作。 – Enigmativity