GroupBy vb.net和c#之间的差异
本文关键字:之间 vb net GroupBy | 更新日期: 2023-09-27 18:20:51
我学习了一个用c#编写代码的linq教程,并尝试将代码片段翻译成vb.net
var employeeGroups = from employee in Employee.GetAllEmployees()
group employee by employee.Deptartment;
我可以把它翻译成扩展方法
Dim group1 = Employee.GetAllEmployees.GroupBy(Function(x) x.Department)
工作正常,但
Dim group = From emp In Employee.GetAllEmployees
Group emp By emp.Department
给了我一个编译错误"into expected"。我找不到任何关于它的信息,但我必须在vb中使用"INTO",而不是在c#中,这对吗?如果是这样,我必须如何调整我的查询以适应c#等价物?
VB.Net具有不同的组语法。试试这个。。
From emp In Employee.GetAllEmployees
Group By Department= emp.Department Into g = Group
Select g
或者简单的
From emp In Employee.GetAllEmployees
Group By Department= emp.Department Into Group