C# 程式來合併序列
讓我們新增兩個序列。
整數陣列。
int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };字串陣列。
string[] stringArray = { "Depp", "Cruise", "Pitt", "Clooney", "Sandler", "Affleck", "Tarantino" };現在,要合併以上兩個序列,請使用 Zip 方法。
ntArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);
讓我們看看完整的程式碼。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
int[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
string[] stringArray = { "Depp", "Cruise", "Pitt", "Clooney", "Sandler", "Affleck", "Tarantino" };
var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two);
foreach (var ele in mergedSeq)
Console.WriteLine(ele);
}
}輸出
1 Depp 2 Cruise 3 Pitt 4 Clooney 5 Sandler 6 Affleck 7 Tarantino
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP