0

我在将 C# 中的这个 LINQ 查询转换为 VB.NET 时遇到了一些问题。

C#:

from row in Users
group row by row.Password_tx into Passes
select new {Password = Passes.Key, Total = Passes.Count()}

我曾尝试在 VB.NET 中执行此操作,但运气不佳。我知道 Into 语法有点不同,但在这种情况下我无法弄清楚。

VB.NET:

from row in Users _
group by pass = row.Password_tx into passes = Group _
select with {.passes.Key, .passes.Count()}
4

2 回答 2

2

这应该这样做:

From row In Users
Group By pass = row.Password_tx Into passes = Group
Select Password = pass, Total = passes.Count

这是我用来确认它工作的示例代码:

Public Class Form1
  Class User
    Friend Property Password_tx As String
    Sub New(pwd As String)
      Password_tx = pwd
    End Sub
  End Class
  Class Users : Inherits Generic.List(Of User)
  End Class

  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim u As New Users
    u.Add(New User("abc"))
    u.Add(New User("bcd"))
    u.Add(New User("abc"))

    Dim v = From row In u
            Group By pass = row.Password_tx Into passes = Group
            Select Password = pass, Total = passes.Count
  End Sub
End Class
于 2013-02-13T20:15:54.160 回答
0

也许你可以试试这个。

from row in Users _
group by pass = row.Password_tx into passes = Group _
select New With {.Password = Passes.Key, _ 
                 .Total = Passes.Count()}
于 2013-02-14T06:57:58.283 回答