C# 中的拼接方法


要拼接 C# 中的列表,請使用拼接方法。

以下是列表 −

var list1 = new List<int>{12, 40};
var list2 = new List<int>{98, 122, 199, 230};

以下是拼接方法 −

var res = list1.Concat(list2);

以下是使用拼接方法的示例 −

示例

 線上演示

using System.Collections.Generic;
using System.Linq;
using System;

public class Demo {
   public static void Main() {

      // two lists
      var list1 = new List<int>{12, 40};
      var list2 = new List<int>{98, 122, 199, 230};
   
      // concat
      var res = list1.Concat(list2);

      foreach(int i in res) {
         Console.WriteLine(i);
      }
   }
}

輸出

12
40
98
122
199
230

更新於: 2020-06-22

173 次瀏覽

開啟你的職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.