简体   繁体   English

我有两个字符串列表,如何从每个列表索引中创建一个字符串?

[英]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.

相关问题 我想在两个列表之间应用除外。 一个列表是MailAddress格式,另一个是String(转换为列表)) - I want to apply Except between two lists. One list is in MailAddress format and other is a String (Converted to list)) 我如何排序列表 <string> 根据每个索引中每个字符串中的数字? - How can i sort a List<string> according to the numbers in each string in each index? 如何通过组合其他两个列表来创建新列表? - How can I create a new list as a result of combing two other lists? 如何格式化列表中的每个字符串? - How can i format each string in the List? 如何为每个根节点子代创建列表列表? - How can I create a List of lists for each root node childs? 如何建立清单 <FileInfo> 来自IEnumerable <string> ? - How can I create a List<FileInfo> from IEnumerable<string>? 如何计算C#字符串中两个紧接着的单词的出现次数? - How can I count occurences of two words following each other in a string in C#? 如何有两个来自不同项目的Window窗体互相显示和隐藏? - How can I have two Window forms, from different projects, show and hide each other? 如何创建具有属性列表之一的行列表 - How can I create a list of rows that have one of a list of properties 如何获取字符串中两个相同字符的索引? - How can i get index of two same character in string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM