2013-12-13 4 views
2

특정 목록의 다른 목록에서 범위를 추가하려면 inbuilt 함수가 generic 목록에 있습니까? 아니면 내 목록을 작성해야합니까?특정 인덱스의 AddRange를 나열 하시겠습니까?

예를 들어

:

내가 내 자신을 작성해야 또는이 작업을 수행 할 수있는 붙박이 기능이있다 (100), 20 (30) :이 예에서

List<int> list1 = new List<int>(); 
List<int> list2 = new List<int>(); 

list1.Add(10); 
list1.Add(20); 
list1.Add(30); 

list2.Add(100); 
//list2.AddRange(list1, 1) Add from list1 from the index 1 till the end 

의리스트 2 3 개 요소를 가지고 있어야 ?

+0

http://msdn.microsoft.com/en-us/library/z883w3dc(v=vs.110).aspx – Shyju

+0

@Shyju 그는 이미 AddRange()를 알고 있습니다. – DGibbs

답변

6

AddRange에 내장,하지만 당신은 LINQ를 사용할 수 없음 : 여기

list2.Add(100); 
list2.AddRange(list1.Skip(1)); 

live example이다. 인쇄에

2
List<int> list1 = new List<int>(); 
List<int> list2 = new List<int>(); 

list1.Add(10); 
list1.Add(20); 
list1.Add(30); 

list2.Add(100); 
list2.InsertRange(1,list1.Skip(1)); 

출력 :

100

20

30

첫 번째를 건너 뛸 것이다하는 LINQ 스킵 방법과 결합 InsertRange 사용할 수

요소. 특정 인덱스 뒤에 삽입하려는 경우.

관련 문제