在 Linq to Object (Enumerables) 中
默认比较器如何解决以下问题?
//The following is essentially a select distinct
var x = from student in class
group student by new {student.MajorId, student.GradeId} into performanceStudentGroup
select new { performanceStudentGroup.Key.MajorId, performanceStudentGroup.Key.GradeId};
显然,为了使上述工作正常,框架必须比较 2 个匿名类型以检查它们是否属于同一组。
它是如何做到的?它如何能够检查比引用指针更多的东西?
该比较器与以下代码有何不同:
var y = (from student in class
select new { student.MajorId, student.GradeId}).Distinct();