[Reserved] List collection in C # IndexOf use the index to determine the location of the first occurrence of an element

List C # in the set operation, and sometimes necessary to determine the position information of the index elements of the object first appears in the List collection, required in this case to set List IndexOf method to determine if the element is present in the collection List, then the method IndexOf returns the index position information is located, and if not it returns -1, IndexOf method signature int IndexOf (T item), item on behalf of judgment object element.

For example, a List <int> list1 set, position information necessary to determine the index list1 set the first occurrence number 6:

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

Evaluates, index = 5.

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link is in C # List collection to use IndexOf to determine the index position _IT little fun house technical elements of the first occurrence .

Guess you like

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