[Reserved] List in C # using GetRange method to get a collection of all the values within a specified range of indexes

Sometimes the need to obtain the position of the element specified index in the range of C # List set to form a new set of List, then the method can be extended to the use of a set of List GetRange method, specifically a method for obtaining GetRange List collection within the specified range all values, GetRange method signature List <T> GetRange (int index, int count), index as the start position of the index, count the number of elements is acquired from the start index.

For example, a List <int> list1 set, 10 stores numbers, starting from the need to obtain list1 set number 5, five contiguous set of new elements, with the following statement:

List<int> list1 = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var resultList= list1.GetRange(4, 5);

The results for the elements set is 5,6,7,8,9 resultList

 

Note: The text reproduced from personal bloggers station technology IT technology small fun house , the original link is in C # using GetRange List collection method to get all the values _IT little fun house technology within a specified range of indexes .

Guess you like

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