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"
网友评论