linq.DefaultIfEmpty

Returns the array, or an array with a specified single element if it is empty

Overloads

  • Array DefaultIfEmpty ()
  • Array DefaultIfEmpty (default)

Array DefaultIfEmpty ()

Returns the array, or an array containing a single value, null in this case

Example

var myArray = [1,3,5];

//Returns [1, 3, 5]
myArray.DefaultIfEmpty();

myArray = [];
//Returns [null];
myArray.DefaultIfEmpty();

Array DefaultIfEmpty (default)

Returns the array, or an array containing the specified default value if empty

Example

var myArray = [1, 2, 3];

//Returns [1, 2, 3];
myArray.DefaultIfEmpty(4);

myArray = [];

//Returns [4]
myArray.DefaultIfEmpty(4);

Last edited Sep 24, 2011 at 11:06 PM by mlorbetske, version 1

Comments

No comments yet.