Actually the question in the title of the topic. There is a collection:
List<int> styleID = new List<int>(); Several IDs have been added to it ( 221432 , 445566 , 998877 , etc.). How to find the element index with the value 998877 ?
A simple way is to call the IndexOf() method:
var indexOfIntegerValue = styleID.IndexOf(998877); In the variable indexOfIntegerValue get the value corresponding to the index number 998877 in the specified collection. In case your collection does not contain such a number (998877), this method will return the value -1 .
You can use Linq , lambda expression and FindIndex method:
list<int> styleID = new List<int>(); int index = styleID.FindIndex(x => x == 998877); FindIndex is not Linq ;) - user227049The List type collection has an IndexOf(T) method.
Source: https://ru.stackoverflow.com/questions/758646/
All Articles