从结构体数组中筛选相关要素,排序等功能,就像数组能执行 SQL 一样
底下为.Net 的代码
请问除了
https://github.com/ahmetb/go-linq还有更好的实现吗
class Program
{
public class Student
{
public int StID;
public string LastName;
}
public class CourseStudent
{
public string CourseName;
public int StID;
}
static Student[] students=new Student[]{
new Student{StID=1,LastName="Carson"},
new Student{StID=2,LastName="Klassen"},
new Student{StID=3,LastName="Fleming"},
};
static CourseStudent[] studentsInCourses=new CourseStudent[]{
new CourseStudent{CourseName="Art",StID=1},
new CourseStudent{CourseName="Art",StID=2},
new CourseStudent{CourseName="History",StID=1},
new CourseStudent{CourseName="History",StID=3},
new CourseStudent{CourseName="Physics",StID=3},
}
static void Main()
{
var query=from s in students
join c in studentsInCourses on s.StID equals c.STID
where c.CourseName=="History"
select.LastName;
foreach(var q in query)
{
Console.WriteLine("Student taking History:{0}",q);
}
}
}