{TOC}
| Namespace: | System.Linq |
| Assembly: | System.Core.dll |
| Extends: | IEnumerable<T> |
Back to
Standard Query Operator IndexEditIntroduction
Compares two sequences and returns true only if the members values, order and count are identical. (This operated was new in the January CTP, it is identical to the
EqualAll Operator that was in previous CTP's).
EditMethod Signatures
// 1 - Return true if the two sequences are equal in values, order and count.
public static bool SequenceEqual<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second)
// 2 - Return true if the two sequences are equal in values, order and count.
// Allows you to specify a custom comparer function.
public static bool SequenceEqual<TSource>(
this IEnumerable<TSource> first,
IEnumerable<TSource> second,
IEqualityComparer<TSource> comparer)EditExceptions
Throws an ArgumentNullException if
first or
second is null.
EditPseudo-code
Overload 1
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
Begin iterating the
first and
second sequences.
Get the next (or first) first element.
Get the next (or first) second element.
If there is no next second element, return false.
Compare the current first and second element using EqualityComparer<TSource>.Default.
If they are NOT equal, return false.
If there are any remaining
second elements (more than the
first sequence has), return false.
Else, return true. The sequence elements are equal in value, order and length.
Overload 2
If
first is null, throw an ArgumentNullException.
If
second is null, throw an ArgumentNullException.
Begin iterating the
first and
second sequences.
Get the next (or first) first element.
Get the next (or first) second element.
If there is no next second element, return false.
Compare the current first and second element using the comparer equality comparer function.
If they are NOT equal, return false.
If there are any remaining
second elements (more than the
first sequence has), return false.
Else, return true. The sequence elements are equal in value, order and length.
EditLoop Count
2 if true, < 2 if false. Iterates through both the
first and
second sequences. Will return false at the first difference.
EditCode Samples
TODO: Needs code sample.