Search code examples
c#asp.netsharpkml

Distinct List Elements


I have a list collection of following type

CoordinateCollection pointCoordinates = new CoordinateCollection();

it adds up list of type vector. I want to remove duplicate entries from the list

I am trying like this

pointCoordinates = pointCoordinates.Distinct();

it gives me an error

cannot implicitly convert type 'system.collections.generic.ienumerable<SharpKML.Base.Vector> to SharpKML.Dom.CoordinateCollection

Please help me in solving this. I want unique set of records


Solution

  • Since CoordinateCollection implements ICollection<Vector> and Vector overrides Equals + GethashCode you can use Distinct. But you need to use the constructor of CoordinateCollection to create a new:

    pointCoordinates = new CoordinateCollection(pointCoordinates.Distinct());
    

    Note that i'm not familiar with SharpKML, i have looked at it's source code.