I need to select distinct highways from a roads collection.
I suppose I could use LINQ for this.
I have (stub code)
Dim roads As List(Of Roads) = myRegion.Roads
Dim highways As New List(Of Highway)
For Each road In roads
If road.RoadType = RoadType.Highway Then
highways.Add(DirectCast(road, Highway))
End If
Next ic
' Now I think sorting them by .Id and then remove duplicates '
Dim myComparer As New HighwayByIdComparer
highways.Sort(myComparer)
C# variants are accepted as well 😉
C#:
(where DistinctBy is an extension method defined in Jon Skeet’s excellent MoreLINQ project)