tags:

views:

246

answers:

1

I am converting a c# LINQ example:

        var query = from m in typeof(string).GetMethods()
                    where m.IsStatic == true
                    orderby m.Name
                    group m by m.Name into g
                    orderby g.Count()
                    select new { name = g.Key, overloads = g.Count() };

In the above C# the g is an IGrouping but in the VB below it's instead an IEnumerable and thus the g.Key isn't resolving.

        Dim query = From m In GetType(String).GetMethods() _
        Where m.IsStatic = True _
        Order By m.Name _
        Group m By m.Name Into g = Group _
        Order By g.Count _
        Select name = g.Key, [overloads] = g.Count()

How do I do this in VB?

+1  A: 

I think what you want is this:

Dim query = From m In GetType(String).GetMethods() _
                        Where m.IsStatic = True _
                        Group m By m.Name Into g = Group _
                        Order By Name, g.Count _
                        Select New With {.MethodName = Name, .Overloads = g.Count()}

Hope that helps.

Jeremy Wiebe
I'd guess that's just implementation differences between C# and VB.NET. Might be interesting to compare the IL generated by the two snippets because the underlying LINQ infrastructure is the same, just the LINQ language implementation differs between the two languages, I think.
Jeremy Wiebe