세 가지 목록 설정 -
// three lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};
var list3 = new List<int>{2, 5, 6}; 이제 Concat mthod를 사용하여 위의 목록을 연결하십시오 -
var res1 = list1.Concat(list2); var res2 = res1.Concat(list3);
다음은 전체 코드입니다 -
예
using System.Collections.Generic;
using System.Linq;
using System;
public class Demo {
public static void Main() {
// three lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};
var list3 = new List<int>{2, 5, 6};
// concat
var res1 = list1.Concat(list2);
var res2 = res1.Concat(list3);
foreach(int i in res2) {
Console.WriteLine(i);
}
}
} 출력
3 4 1 2 3 2 5 6