我似乎對此有點卡住,但我在Linq的經歷並不好。基本上,我有這樣的事情代碼:Linq加入Xs,Ys入點
public class Point
{
public int X { get; set; }
public int Y { get; set; }
}
public class B
{
public List<Point> Points { get; set; }
public B(IEnumerable<int> Xs, IEnumerable<int> Ys)
{
// How to best combine Xs and Ys into Points ?
}
}
現在,我該如何填寫該構造適當加入了這些集合?我通常會使用.Join()
,但沒有內鍵可以加入。它也應該能夠處理一個數組比另一個數組少的元素或爲空的機會(絕不應該發生,但這是可能的)。
你不知道它,但你正在尋找一個「zip」函數。這是我最喜歡的鏈接:[如何在C#中執行Python的zip?](http://stackoverflow.com/questions/2427015/how-to-do-pythons-zip-in-c) – Gabe 2010-06-21 19:45:20
這就是爲什麼微軟添加了將.NET擴展方法擴展到.NET 4.0。 – Steven 2010-06-21 19:46:27