【问题标题】:Merging two Arrays using LinQ使用 LinQ 合并两个数组
【发布时间】:2014-09-28 12:07:32
【问题描述】:

我有两个arrays

var students  = new [] {"Elisa" ,"Sarah", "Frank","Frederic"};

var votes  = new[] {90, 70, 40,80};

如果可能,我如何使用linq 打印这样的内容?

"Elisa 90"
"Sarah 70" 
"Frank 40"
"Frederic 80"

【问题讨论】:

    标签: c# arrays linq


    【解决方案1】:

    你可以使用Linq.Zip

    var students = new[] { "Elisa", "Sarah", "Frank", "Frederic" };
    var votes = new[] { 90, 70, 40, 80 };
    var studendsAndVotes = students.Zip(votes, (student, vote) => student + " " + vote);  
    

    来自 MSDN
    Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多