C# 不同的列表元素
我有以下类型的列表集合C# 不同的列表元素,c#,asp.net,sharpkml,C#,Asp.net,Sharpkml,我有以下类型的列表集合 CoordinateCollection pointCoordinates = new CoordinateCollection(); 它将类型向量的列表相加。 我想从列表中删除重复的条目 我正在这样努力 pointCoordinates = pointCoordinates.Distinct(); 这给了我一个错误 cannot implicitly convert type 'system.collections.generic.ienumerable<Sh
CoordinateCollection pointCoordinates = new CoordinateCollection();
它将类型向量的列表相加。
我想从列表中删除重复的条目
我正在这样努力
pointCoordinates = pointCoordinates.Distinct();
这给了我一个错误
cannot implicitly convert type 'system.collections.generic.ienumerable<SharpKML.Base.Vector> to SharpKML.Dom.CoordinateCollection
无法将类型“system.collections.generic.ienumerable”隐式转换为SharpKML.Dom.CoordinateCollection
请帮我解决这个问题。我需要唯一的记录集,因为
协调收集实现了ICollection
和Vector
覆盖等于+GethashCode
您可以使用Distinct
。但是您需要使用CoordinatedCollection
的构造函数来创建新的:
pointCoordinates = new CoordinateCollection(pointCoordinates.Distinct());
请注意,我不熟悉SharpKML,我已经查看了它。Distinct将返回一个IEnumerable
。您无法将该类型分配给CoordinatedCollection
实例,因为即使是IEnumerable
它也可能不是CoordinatedCollection
的实例
如果您需要CoordinatedCollection
的实例,请创建/使用将IEnumerable
作为输入的构造函数,否则如果IEnumerable
将这样声明您的变量。如消息所述,无法将类型为system.collections.generic.ienumerable
的对象隐式分配给类型为SharpKML.Dom.CoordinateCollection
的对象。我建议使用他们的类型转换方法之一(有文档记录)。是您再次读取错误消息时导致的错误。我认为这已经足够清楚了。使用另一个变量分配结果。谢谢Tim Schmelter。