Enumerable::SequenceEqual<TSource> Method (IEnumerable<TSource>, IEnumerable<TSource>)
Determines whether two sequences are equal by comparing the elements by using the default equality comparer for their type.
Assembly: System.Core (in System.Core.dll)
[ExtensionAttribute] public: generic<typename TSource> static bool SequenceEqual( IEnumerable<TSource>^ first, IEnumerable<TSource>^ second )
The type of the elements of the input sequences.
Return ValueType: System::Boolean
true if the two source sequences are of equal length and their corresponding elements are equal according to the default equality comparer for their type; otherwise, false.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
The method enumerates the two source sequences in parallel and compares corresponding elements by using the default equality comparer for TSource, Default. The default equality comparer, Default, is used to compare values of the types that implement the IEqualityComparer<T> generic interface. To compare a custom data type, you need to implement this interface and provide your own GetHashCode and Equals methods for the type.
The following code examples demonstrate how to use to determine whether two sequences are equal. In the first two examples, the method determines whether the compared sequences contain references to the same objects. In the third and fourth examples, the method compares the actual data of the objects within the sequences.
In this example the sequences are equal.
The following code example compares two sequences that are not equal. Note that the sequences contain identical data, but because the objects that they contain have different references, the sequences are not considered equal.
If you want to compare the actual data of the objects in the sequences instead of just comparing their references, you have to implement the IEqualityComparer<T> generic interface in your class. The following code example shows how to implement this interface in a custom data type and provide GetHashCode and Equals methods.
After you implement this interface, you can use sequences of Product objects in the method, as shown in the following example.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.