Find index of a value in an array

前端 未结 8 1566
傲寒
傲寒 2020-11-29 22:41

Can linq somehow be used to find the index of a value in an array?

For instance, this loop locates the key index within an array.

for (int i = 0; i &         


        
8条回答
  •  我在风中等你
    2020-11-29 23:09

    Just posted my implementation of IndexWhere() extension method (with unit tests):

    http://snipplr.com/view/53625/linq-index-of-item--indexwhere/

    Example usage:

    int index = myList.IndexWhere(item => item.Something == someOtherThing);
    

提交回复
热议问题