簡體   English   中英

LINQ從兩個長度相同的集合中選擇

[英]LINQ Select from two Collections with same length

var listA = new List<string> {"One", "Two", "Three"};
var listB = new List<int> {1, 2, 3};
var listC = new List<Tuple<string, int>>();

在這里,我有兩個長度相同的列表。 有沒有辦法用LINQ填充第三個listC

"One", 1
"Two", 2
"Three", 3

我認為你正在尋找Zip擴展方法:

var listA = new List<string> { "One", "Two", "Three" };
var listB = new List<int> { 1, 2, 3 };
var listC = listA.Zip(listB, (s, i) => new Tuple<string, int>(s, i)).ToList();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM