我有以下内容
Dim query = From city In myCountry.Cities
From street In city.Streets
Select New StreetInfo With {.Name = street.Name, .Index = street.Index}
Distinct
现在。我 remarqued 如果我有多个相同的街道(具有相同的 Name
and Index
),StreetInfo 列表包含所有重复项...
我应该如何为生成的 StreetInfo 值集合指定真正不同的值?
比如,StreetInfo
类定义如下:
Public Class StreetInfo
Public Property Name As String
Public Property Index As Integer
End Class
最佳答案
Distinct
使用默认的相等比较器,这意味着您必须覆盖 StreetInfo
上的 Equals
和 GetHashCode
> 让它工作。
关于.net - LINQ 中的 Distinct 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7677428/