[英]Can someone explain why I'm getting an ambiguous invocation error for this?
我有一個要創建的集合的簡單對象。 從該集合中,我需要找到具有相同TransitMapSegmentID的重復項。
public class LineString
{
public int TransitLineID { get; set; }
public string TransitLineName { get; set; }
public int TransitMapSegmentID { get; set; }
public string HexColor { get; set; }
public double[][] Coordinates { get; set; }
}
var lineStrings = new List<LineString>();
使用下面的代碼,我從下面的lambda表達式中收到“歧義調用匹配”錯誤。 誰能解釋為什么?
var result = lineStrings
.Where(a => lineStrings
.Count(b => b.TransitMapSegmentID == a.TransitMapSegmentID) > 1);
如果要根據其TransitMapSegmentID
查找所有重復的行,請使用Enumerable.GroupBy
:
var result = lineStrings
.GroupBy(ls => ls.TransitMapSegmentID)
.Where(grp => grp.Count() > 1)
.SelectMany(grp => grp);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.