1
Q
組合3個序列
A
回答
2
您可以再次使用郵編:
arr1.Zip(arr2, (a1, a2) => new { a1, a2 })
.Zip(arr3, (a12, a3) => a12.a1 + a12.a2 + a3)
或
arr1.Zip(arr2, (a1, a2) => a1 + a2)
.Zip(arr3, (a12, a3) => a12 + a3)
前者版本避免了一個額外的字符串連接。
0
我更喜歡使用自定義Zip,它需要儘可能多的序列。
public static IEnumerable Zip(
this IEnumerable first,
IEnumerable second,
IEnumerable third,
Func resultSelector)
{
Contract.Requires(
first != null && second != null && third != null && resultSelector != null);
using (IEnumerator iterator1 = first.GetEnumerator())
using (IEnumerator iterator2 = second.GetEnumerator())
using (IEnumerator iterator3 = third.GetEnumerator())
{
while (iterator1.MoveNext() && iterator2.MoveNext() && iterator3.MoveNext())
{
yield return resultSelector(iterator1.Current, iterator2.Current, iterator3.Current);
}
}
}
這基本上是Jon Skeet's implementation一個額外的參數,因此所有歸功於他。 ;我相信這有some advantages in some scenarios,否則你會需要中間對象。我絕對認爲它更清晰。
相關問題
- 1. 將3個元組列表合併到一個新列表中
- 2. Excel - 將多列組合成一列3
- 3. 組合3個花車?
- 4. 合併3個列表
- 5. 3數組成1個陣列的所有組合(代碼內)
- 6. 多個列表的排序組合
- 7. C#Linq按鍵組合多個序列
- 8. 通過3個組合中的5個組合循環
- 9. 將3個列表組合成一個字母的問題
- 10. 使用Python在2個組合數組中排列序列
- 11. 序列化組合對象
- 12. 彙總組合序列
- 13. 爲有序集合組合散列
- 14. 在PHP號碼建立關聯數組 - 合併3個陣列
- 15. 表中的3列中的多個組合行
- 16. SQLite獲取使用3個表格組合的對象列表
- 17. 來自陣列的3個值的組合
- 18. 將3個列表比較和重新組合成一個列表?
- 19. 多次組合3個相對佈局
- 20. SQL組合3個語句;可能嗎?
- 21. SQL - 組合3個表問題
- 22. 如何組合3個或更多CompletionStages?
- 23. 嵌套加入以組合3個表
- 24. Python返回一個列表的組合列表序列
- 25. 組合兩個數組1個陣列
- 26. Flexbox模式1/3/3列和行組合
- 27. 合併列表3
- 28. 結合3個數組合併爲一個
- 29. 使用`組合`3組合或以上組合使用
- 30. c#按升序排序組合列表
173K ??那173或173,000?看起來像我可以閉上眼睛,並按照你的建議超人:)是我張貼的鏈接還包含正確的答案? – 2010-05-04 11:52:16
@As:是的,鏈接基本上與我的片段中的第二部分基本相同。 – 2010-05-04 12:13:10