用于LINQ查询的VB和IGrouping

时间:2020-12-11 14:31:38

I am converting a c# LINQ example:

我正在转换一个c#LINQ示例:

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.

在上面的C#中,g是一个IGrouping,但是在VB下面它取而代之的是IEnumerable,因此g.Key没有解析。

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?

我怎么在VB中这样做?

1 个解决方案

#1


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.

希望有所帮助。

#1


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.

希望有所帮助。