直到最近,我在LINQ中使用Distinct从表中选择一个不同的类别(枚举).这工作正常.
我现在需要在包含类别和国家(两个枚举)的类中区分它.The Distinct现在不起作用.
我究竟做错了什么?
Sti*_*gar 21
我相信这篇文章解释了你的问题:http: //blog.jordanterrell.com/post/LINQ-Distinct()-does-not-work-as-expected.aspx
上述链接的内容可以通过说明可以通过执行以下操作来替换Distinct()方法来总结.
var distinctItems = items
.GroupBy(x => x.PropertyToCompare)
.Select(x => x.First());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16700 次 |
| 最近记录: |