linq.IndexOf

Determines the index of a particular element in the array

Overloads

  • int IndexOf (element)
  • int IndexOf (element, equalityComparer)

int IndexOf (element)

Returns the index if element is found in the array, -1 otherwise

Example

var myArray = [1,3,5];
//Returns 1
myArray.IndexOf(3);

int IndexOf (element, equalityComparer)

Returns the index if, when equalityComparer is evaluated on any one element in the array (as the first parameter) and element (as the second), the result is true. If no match is found, -1 is returned

Example

var myArray = [{Field:1}, {Field:2}, {Field:3}];

//Returns 2
myArray.IndexOf(3, "(a, b) => a.Field == b");

Last edited Sep 23, 2011 at 6:12 AM by mlorbetske, version 1

Comments

No comments yet.