I am trying to convert the following LINQ code from C# to VB.NET. Here is the C# followed by my attempt at VB. In VB I would like to declare rowList as IEnumerable(Of IGrouping(Of Char, String)) but it returns an IEnumerable(Of IEnumerable(Of Char, String)).
string rows = "ABC";
string cols = "123";
string[] squares = (from r in rows from c in cols select "" + r + c).ToArray();
IEnumerable<IGrouping<Char, String>> rowList = (from r in rows from s in squares where s.Contains(r) group s by r into g select g);
Dim rows As String = "ABC"
Dim cols As String = "123"
Dim squares As String() = (From r In rows From c In cols Select "" & r & c).ToArray()
Dim rowList = (From r In rows From s In squares Where s.StartsWith(r) Group By r Into g = Group Select g).Dump("rowList")
There are differences between Linq in VB .NET and C#. If you want the return type for the Linq statement in VB .NET to be IEnumerable(Of IGrouping(Of Char, String)) write the Linq statement as follows:
This way you’re dealing with a GroupedEnumerable and not an Enumerable of Enumerable.