Reputation: 139
I am getting the above error. I am not able to retrieve the results of the query. The error happens in for each statement. Below is the code. I am learning LINQ and running the code from https://dotnetfiddle.net/# Below is the code
Imports System
Imports System.Linq
imports System.Collections.Generic
Public Module Module1
public class test
public count as integer
public grp1 as string
public grp2 as String
public sub new(ByVal cnt as integer, ByVal g1 as string, ByVal g2 as String)
count = cnt
grp1 = g1
grp2 = g2
end sub
end class
Public Sub Main()
Dim list = New List(Of Tuple(Of Integer, string, String))
list.Add(New Tuple(Of Integer, string, String)(5, "xxx", "green"))
list.Add(New Tuple(Of Integer, string, String)(5, "yyy", "blue"))
list.Add(New Tuple(Of Integer, string, String)(20, "aaa", "orange"))
list.Add(New Tuple(Of Integer, string, String)(20, "aaa", "yellow"))
list.Add(New Tuple(Of Integer, string, String)(20, "ccc", "magenta"))
' Group tuples by their first item.
' ... TupleGroup is an identifier name.
Dim result = From v In list Group By v.Item1, v.Item2 Into Group, cnt = count(v.Item3) select new test(cnt, Item1, Item2)
' Loop over each group and its items. ERROR OUT
For Each value In result
Next
End Sub
End Module
Upvotes: 0
Views: 203
Reputation: 24901
When you are using cnt = count(v.Item3)
you don't need to provide a parameter to this function, because the data that you are using is already grouped.
Change
Dim result = From v In list Group By v.Item1, v.Item2 _
Into Group, cnt = count(v.Item3) select new test(cnt, Item1, Item2)
to
Dim result = From v In list Group By v.Item1, v.Item2 _
Into Group, cnt = count() select new test(cnt, Item1, Item2)
Upvotes: 1