[Reserved] List C # in collection method using InsertRange insert another set list in the specified location

During operation of the set of List C #, if a new element is inserted in the set of objects in a certain position, can be operated using the Insert method. In fact, a set of List also provides another set inserted in a particular position, then the entire set of data is written to the other current collection. Method InsertRange List collection class is to be inserted into a specified position set another set of methods, the method signature InsertRange InsertRange (int index, IEnumerable <T> collection). Representative insert index specified position, collection represents a set of other data.

For example as follows: list1 and list2 set intL type are set, there is a service requirement list2 insert the whole set of the fifth set of positions list1, list2 collection element is inserted into the same position in the set of elements list. Specific achieve the following:

 List<int> list1 = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 List<int> list2 = new List<int>() { 101, 102, 103, 104, 105 };
 list1.InsertRange(5, list2);

The results obtained for the final list1 1,2,3,4,101,102,103,104, 105,5, 6, 7, 8, 9, 10.

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link in C # using InsertRange List collection method to insert another list collection _IT technology interesting small house in the specified location .

Guess you like

Origin www.cnblogs.com/xu-yi/p/10993503.html