หากต้องการเชื่อมต่อรายการใน C # ให้ใช้วิธี Concat
ต่อไปนี้เป็นรายการ -
var list1 = new List<int>{12, 40};
var list2 = new List<int>{98, 122, 199, 230}; นี่คือวิธี Concat -
var res = list1.Concat(list2);
ต่อไปนี้เป็นตัวอย่างการทำงานกับวิธี Concat -
ตัวอย่าง
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