linq.Single

Gets the only element in the array. An exception is thrown if the array contains no or more than one elements.

Overloads

  • Object Single ()
  • Object Single (condition)

Object Single ()

Gets the first element in the array
var myArray = [1, 2, 3, 4];
//Throws an exception
myArray.Single();

myArray = [1];
//Returns 1
myArray.Single();

Object Single (condition)

Gets the only element in the array where the specified condition is met

Example

var myArray = [1,3,4,5];
//Returns 4
myArray.Single("x => x % 2 == 0");

//Throws an exception
myArray.Single("x => x % 2 == 1");

Last edited Sep 24, 2011 at 6:36 AM by mlorbetske, version 1

Comments

No comments yet.