Queryable.SequenceEqual 메서드

정의

두 시퀀스가 서로 같은지 확인합니다.Determines whether two sequences are equal.

오버로드

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

기본 같음 비교자를 통해 요소를 비교하여 두 시퀀스가 서로 같은지 확인합니다.Determines whether two sequences are equal by using the default equality comparer to compare elements.

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>를 통해 요소를 비교하여 두 시퀀스가 서로 같은지 확인합니다.Determines whether two sequences are equal by using a specified IEqualityComparer<T> to compare elements.

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>)

기본 같음 비교자를 통해 요소를 비교하여 두 시퀀스가 서로 같은지 확인합니다.Determines whether two sequences are equal by using the default equality comparer to compare elements.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static bool SequenceEqual(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2);
public static bool SequenceEqual<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2);
static member SequenceEqual : System.Linq.IQueryable<'Source> * seq<'Source> -> bool
<Extension()>
Public Function SequenceEqual(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource)) As Boolean

형식 매개 변수

TSource

입력 시퀀스 요소의 형식입니다.The type of the elements of the input sequences.

매개 변수

source1
IQueryable<TSource>

해당 요소를 source2의 요소와 비교할 IQueryable<T>입니다.An IQueryable<T> whose elements to compare to those of source2.

source2
IEnumerable<TSource>

해당 요소를 첫 번째 시퀀스의 요소와 비교할 IEnumerable<T>입니다.An IEnumerable<T> whose elements to compare to those of the first sequence.

반환

Boolean

두 소스 시퀀스의 길이가 같고 해당 요소가 같은 것으로 비교되면 true이고, 그렇지 않으면 false입니다.true if the two source sequences are of equal length and their corresponding elements compare equal; otherwise, false.

예외

source1 또는 source2null인 경우source1 or source2 is null.

예제

다음 코드 예제에서는를 사용 하 여 SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) 두 시퀀스가 서로 같은지 여부를 확인 하는 방법을 보여 줍니다.The following code example demonstrates how to use SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) to determine whether two sequences are equal. 이 예제에서 시퀀스는 동일 합니다.In this example the sequences are equal.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void SequenceEqualEx1()
{
    Pet pet1 = new Pet { Name = "Turbo", Age = 2 };
    Pet pet2 = new Pet { Name = "Peanut", Age = 8 };

    // Create two lists of pets.
    List<Pet> pets1 = new List<Pet> { pet1, pet2 };
    List<Pet> pets2 = new List<Pet> { pet1, pet2 };

    // Determine if the lists are equal.
    bool equal = pets1.AsQueryable().SequenceEqual(pets2);

    Console.WriteLine(
        "The lists {0} equal.",
        equal ? "are" : "are not");
}

/*
    This code produces the following output:

    The lists are equal.
*/

Class Pet
    Public Name As String
    Public Age As Integer
End Class

Shared Sub SequenceEqualEx1()
    Dim pet1 As New Pet With {.Name = "Turbo", .Age = 2}
    Dim pet2 As New Pet With {.Name = "Peanut", .Age = 8}

    ' Create two lists of pets.
    Dim pets1 As New List(Of Pet)(New Pet() {pet1, pet2})
    Dim pets2 As New List(Of Pet)(New Pet() {pet1, pet2})

    ' Determine if the lists are equal.
    Dim equal As Boolean = pets1.AsQueryable().SequenceEqual(pets2)

    ' Display the output.
    Dim text As String = IIf(equal, "are", "are not")
    MsgBox("The lists " & text & " equal.")
End Sub

'This code produces the following output:

'The lists are equal.

다음 코드 예제에서는 같지 않은 두 시퀀스를 비교 합니다.The following code example compares two sequences that are not equal.

class Pet
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public static void SequenceEqualEx2()
{
    Pet pet1 = new Pet() { Name = "Turbo", Age = 2 };
    Pet pet2 = new Pet() { Name = "Peanut", Age = 8 };

    // Create two lists of pets.
    List<Pet> pets1 = new List<Pet> { pet1, pet2 };
    List<Pet> pets2 = new List<Pet> {
        new Pet { Name = "Turbo", Age = 2 },
        new Pet { Name = "Peanut", Age = 8 }
    };

    // Determine if the lists are equal.
    bool equal = pets1.AsQueryable().SequenceEqual(pets2);

    Console.WriteLine("The lists {0} equal.", equal ? "are" : "are NOT");
}

/*
    This code produces the following output:

    The lists are NOT equal.
*/

Class Pet
    Public Name As String
    Public Age As Integer
End Class

Shared Sub SequenceEqualEx2()
    Dim pet1 As New Pet With {.Name = "Turbo", .Age = 2}
    Dim pet2 As New Pet With {.Name = "Peanut", .Age = 8}

    ' Create two lists of pets.
    Dim pets1 As New List(Of Pet)()
    pets1.Add(pet1)
    pets1.Add(pet2)

    Dim pets2 As New List(Of Pet)()
    pets2.Add(New Pet With {.Name = "Turbo", .Age = 2})
    pets2.Add(New Pet With {.Name = "Peanut", .Age = 8})

    ' Determine if the lists are equal.
    Dim equal As Boolean = pets1.AsQueryable().SequenceEqual(pets2)

    ' Display the output.
    Dim text As String = IIf(equal, "are", "are not")
    MsgBox("The lists " & text & " equal.")
End Sub

' This code produces the following output:

' The lists are not equal.

설명

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) .The SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) method generates a MethodCallExpression that represents calling SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression Execute<TResult>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source1 .It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source1 .The query behavior that occurs as a result of executing an expression tree that represents calling SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>) depends on the implementation of the type of the source1 parameter. 예상 되는 동작은 두 소스 시퀀스가 동일한 지 여부를 확인 하는 것입니다.The expected behavior is that it determines if the two source sequences are equal.

적용 대상

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)

지정된 IEqualityComparer<T>를 통해 요소를 비교하여 두 시퀀스가 서로 같은지 확인합니다.Determines whether two sequences are equal by using a specified IEqualityComparer<T> to compare elements.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static bool SequenceEqual(System::Linq::IQueryable<TSource> ^ source1, System::Collections::Generic::IEnumerable<TSource> ^ source2, System::Collections::Generic::IEqualityComparer<TSource> ^ comparer);
public static bool SequenceEqual<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource> comparer);
public static bool SequenceEqual<TSource> (this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource>? comparer);
static member SequenceEqual : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> bool
<Extension()>
Public Function SequenceEqual(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource), comparer As IEqualityComparer(Of TSource)) As Boolean

형식 매개 변수

TSource

입력 시퀀스 요소의 형식입니다.The type of the elements of the input sequences.

매개 변수

source1
IQueryable<TSource>

해당 요소를 source2의 요소와 비교할 IQueryable<T>입니다.An IQueryable<T> whose elements to compare to those of source2.

source2
IEnumerable<TSource>

해당 요소를 첫 번째 시퀀스의 요소와 비교할 IEnumerable<T>입니다.An IEnumerable<T> whose elements to compare to those of the first sequence.

comparer
IEqualityComparer<TSource>

요소를 비교하는 데 사용할 IEqualityComparer<T>입니다.An IEqualityComparer<T> to use to compare elements.

반환

Boolean

두 소스 시퀀스의 길이가 같고 해당 요소가 같은 것으로 비교되면 true이고, 그렇지 않으면 false입니다.true if the two source sequences are of equal length and their corresponding elements compare equal; otherwise, false.

예외

source1 또는 source2null인 경우source1 or source2 is null.

설명

SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>)메서드는 자신을 MethodCallExpression 생성 된 제네릭 메서드로 호출 하는을 생성 합니다 SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) .The SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) method generates a MethodCallExpression that represents calling SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) itself as a constructed generic method. 그런 다음 MethodCallExpression Execute<TResult>(Expression) IQueryProvider Provider 매개 변수의 속성이 나타내는의 메서드에를 전달 합니다 source1 .It then passes the MethodCallExpression to the Execute<TResult>(Expression) method of the IQueryProvider represented by the Provider property of the source1 parameter.

호출을 나타내는 식 트리를 실행 한 결과로 발생 하는 쿼리 동작은 SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) 매개 변수의 형식 구현에 따라 달라 집니다 source1 .The query behavior that occurs as a result of executing an expression tree that represents calling SequenceEqual<TSource>(IQueryable<TSource>, IEnumerable<TSource>, IEqualityComparer<TSource>) depends on the implementation of the type of the source1 parameter. 예상 되는 동작은를 사용 하 여 요소를 비교 하는 두 소스 시퀀스가 같은지 확인 하는 것입니다 comparer .The expected behavior is that it determines if the two source sequences are equal by using comparer to compare elements.

적용 대상