2014-02-11 48 views
0

我有以下類型鮮明列表元素

CoordinateCollection pointCoordinates = new CoordinateCollection(); 

列表集合加起來型載體的名單。 我想從列表中刪除重複項

我想這樣

pointCoordinates = pointCoordinates.Distinct(); 

它給了我一個錯誤

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

請幫我解決這個。我想唯一的一組記錄

+0

是您清除或分配時引起的錯誤 –

+1

再次讀取錯誤消息。我認爲這很清楚。使用另一個變量來分配結果。 –

回答

1

由於CoordinateCollection工具ICollection<Vector>Vector覆蓋Equals + GethashCode可以使用Distinct。但是,你需要使用的CoordinateCollection構造函數來創建一個新:

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

請注意,我不熟悉SharpKML,我已經看過它的source code

+0

謝謝Tim Schmelter。 –

0

不同的是要返回IEnumerable<SharpKML.Base.Vector>。您不能將該類型分配給您的CoordinateCollection實例,因爲即使是IEnumerable<SharpKML.Base.Vector>它也可能不是CoordinateCollection的實例。

如果你需要的CoordinateCollection實例創建/使用一個構造函數,將採取IEnumerable<SharpKML.Base.Vector>作爲輸入,否則如果IEnumerable<SharpKML.Base.Vector>會做然後聲明您的變量本身。

1

正如消息所述,您不能將類型爲system.collections.generic.ienumerable<SharpKML.Base.Vector>的對象隱式分配給SharpKML.Dom.CoordinateCollection類型的對象。我會建議使用他們的類型轉換方法之一(記錄here)。