[英]I have two Lists of string how can i create a string from each List index with the other one?
For example I have a List: 例如,我有一个列表:
[0] daniel
[1] moses
Now the second List: 现在第二个列表:
[0] hello world
[1] hi everyone
I want to build a new List of string that's will be: 我想建立一个新的字符串列表,它将是:
[0] daniel hellow world
[1] moses hi everyone
How can I do it? 我该怎么做?
You can use Linq / Enumerable.Zip : 您可以使用Linq / Enumerable.Zip :
var list1 = new List<string>() {"daniel", "moses"};
var list2 = new List<string>() { "hello world", "hi everyone" };
var resultList = list1.Zip(list2, (a, b) => a + " " + b)
.ToList();
您可以使用LINQ Zip
方法:
var result = first.Zip(second, (f, s) => string.Format("{0} {1}", f, s));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.