2016-10-04 5 views
0

私はリスト(StoreList)のリストを持っています。すべての店舗で使用可能なすべてのりんごを数える必要があります。それをどうするかわからない。カウント

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を使って、すべての店舗で使用可能なすべてのリンゴをどのようにカウントするのですか?

答えて

2

あなたはこれを試すSum に機能を割り当てるのを忘れています

Dim count As Integer = StoreList.Sum(Function(inner) _ 
     inner.Where(Function(x As myObject) _ 
       x.What = "Apple" And x.Available).Count) 
+0

@D_Bester - このコードは私のために動作します。 – Enigmativity