8,497
社区成员
发帖
与我相关
我的任务
分享
class Student
{
public string name { get; set; }
public int value { get; set; }
public Student(string _name, int _value)
{
name = _name;
value = _value;
}
}
string GroupByWhat(Student stu,string s1)
{
if (s1 == "name")
{
return stu.name;
}
else
{
return stu.value.ToString();
}
}
void Main()
{
List<Student> list = new List<Student>();
list.Add(new Student(" stu1",1));
list.Add(new Student(" stu2",2));
list.Add(new Student(" stu2", 3));
list.Add(new Student(" stu4", 3));
var query = from l in list
group l by GroupByWhat(l,"value") into m
select m;
}