linq.SequenceEquals

Determines whether two Arrays contain value-equal members and are equal in length

Overloads

  • bool SequenceEquals (array)
  • bool SequenceEquals (array, comparator)
  • bool SequenceEquals (array, comparator, ignoreOrder)

bool SequenceEquals (array)

Determines whether two Arrays contain value-equal members.
Note: This overload compares elements in the arrays in order

Example

var myArray = [5, 3, 2, 1, 7, 23];
var myOtherArray = [5, 3, 2, 1, 7, 23];

//Returns true
myArray.SequenceEquals(myOtherArray);

myOtherArray = [5, 3, 2, 1, 7, 24];

//Returns false
myArray.SequenceEquals(myOtherArray);

myOtherArray = [5, 3, 2, 1, 7];

//Returns false
myArray.SequenceEquals(myOtherArray);

myOtherArray = [5, 3, 2, 1, 23, 7];

//Returns false
myArray.SequenceEquals(myOtherArray);

bool SequenceEquals (array, comparator)

Determines whether two Arrays contain value-equal members, comparing the values using the specified comparator
Note: This overload compares elements in the arrays in order

Example

var myArray = [{x: 5}, {x: 3}, {x: 2}, {x: 1}, {x: 7}, {x: 23}];
var myOtherArray = [{x: 5}, {x: 3}, {x: 2}, {x: 1}, {x: 7}, {x: 23}];

//Returns true
myArray.SequenceEquals(myOtherArray, "(a, b) => a.x == b.x");

myOtherArray = [{x: 5}, {x: 3}, {x: 2}, {x: 1}, {x: 7}, {x: 24}];

//Returns false
myArray.SequenceEquals(myOtherArray, "(a, b) => a.x == b.x");

bool SequenceEquals (array, comparator, ignoreOrder)

Determines whether two Arrays contain value-equal members, if ignoreOrder is true, the elements in the two arrays may be in any order and, as long as the length of the arrays match and each element in each array is contained in the other with the same frequencey, the result is true.
Note: If null is passed for comparator, the default comparator is used

Example

var myArray = [5, 3, 2, 1, 7, 23];
var myOtherArray = [5, 23, 2, 1, 7, 3];

//Returns true
myArray.SequenceEquals(myOtherArray, null, true);

myOtherArray = [5, 3, 2, 1, 7, 23];

//Returns true
myArray.SequenceEquals(myOtherArray, null, true);

myOtherArray = [5, 3, 2, 1, 7];

//Returns false
myArray.SequenceEquals(myOtherArray, null, true);

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

Comments

No comments yet.