美文网首页Linq
System.Linq.Zip

System.Linq.Zip

作者: 呼啦啦啦就是飞 | 来源:发表于2021-11-05 15:03 被阅读0次

System.Linq.Zip函数作用为将两个序列对应元素合为一个元素

public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector);

注意:
参数first、second中first序列可以比second序列长或相等
示例:

List<string> stringList1 = new List<String> { "Freesc", "Joshua", "Ken" };
List<string> stringList2 = new List<String> { "Huang", "Guan", "Wang" };
List<string> resultList = new List<string>();
foreach (var item in stringList1.Zip(stringList2, (first, second) => first + "" + second)) {
    resultList.Add(item);
}

输出结果:
"FreescHuang"
"JoshuaGuan"
"KenWang"

示例:

List<string> stringList1 = new List<String> { "Freesc", "Joshua", "Ken" };
List<string> stringList2 = new List<String> { "Huang", "Guan" };
List<string> resultList = new List<string>();
foreach (var item in stringList1.Zip(stringList2, (first, second) => first + "" + second)) {
    resultList.Add(item);
}

输出结果:
"FreescHuang"
"JoshuaGuan"
"Ken"

相关文章

  • System.Linq.Zip

    System.Linq.Zip函数作用为将两个序列对应元素合为一个元素 注意:参数first、second中fir...

网友评论

    本文标题:System.Linq.Zip

    本文链接:https://www.haomeiwen.com/subject/harrzltx.html