tags:

views:

55

answers:

2

These static Array methods have me puzzled. They seem to do the same things. Are they available for older legacy code?

Array.IndexOf
Array.FindIndex

Array.LastIndexOf
Array.FindLastIndex
A: 

FindIndex takes a predicate.

Two different ways to find 6 in:

var nums = new[]{1,3,7,6,5};

First even:

Array.FindIndex(nums, val=>val % 2 == 0);

Value:

Array.IndexOf(nums, 6);
Matthew Flaschen
A: 

One accepts an item to match. The other other accepts a function that checks an item and return true if matches, false if it does not.

For example:

var x = {1,2,3,4,5,6};
int i = Array.IndexOf(x, 2);
int j = Array.FindIndex(x, a => a == 2);
Joel Coehoorn