读书人

这个linq用vb.net的语法如何写

发布时间: 2012-06-01 16:46:36 作者: rapoo

这个linq用vb.net的语法怎么写?
我有一个class(clsStudent),里面有StudentID,Name,Age,ClassID,Gender

然后我有个 lstStudent是clsStudent的list

我现在想知道在lstStudent里面有多少学生有相同Age,ClassID,Gender;并把这些学生的Name和StudentID打印出来

我在网上看的似乎语法不对,麻烦指点下

VB.NET code
from s as clsStudent in lstStudent group s by new {s.Age, s.Gender, s.ClassID} into mygrp ...‘这样就通不过,后面不会写了

如果我这么写不对,那如何才能写才能达到我的要求呢

谢谢

[解决办法]
var query=from s in lstStudent
group s by new {s.Age, s.Gender, s.ClassID} into g
select new
{
Age=g.Key.Age,
Gender=g.Key.Gender,
ClassID=g.Key.ClassID,
StudentID=string.Join(",",g.Select(x=>x.StudentID).ToArray()),//假定 StudentID为string 类型
Name=string.Join(",",g.Select(x=>x.Name).ToArray()),//假定 Name为string 类型
Count=g.Count()
};

读书人网 >VB Dotnet

热点推荐