매개 변수

첫 번째 시퀀스에 해당 요소가 있는 경우 반환되는 시퀀스에서 해당 요소를 제거할 IEnumerable<T>입니다.An IEnumerable<T> whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

Public Class ProductA
Inherits IEquatable(Of ProductA)
Public Property Name As String
Public Property Code As Integer
Public Function Equals(ByVal other As ProductA) As Boolean
If other Is Nothing Then Return False
Return Me.Name = other.Name AndAlso Me.Code = other.Code
End Function
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Return Equals(TryCast(obj, ProductA))
End Function
Public Overrides Function GetHashCode() As Integer
Return (Name, Code).GetHashCode()
End Function
End Class

이 인터페이스를 구현한 후에는 다음 예제와 같이 Except<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) 메서드에서 ProductA 개체의 시퀀스를 사용할 수 있습니다.After you implement this interface, you can use sequences of ProductA objects in the Except<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) method, as shown in the following example:

매개 변수

첫 번째 시퀀스에 해당 요소가 있는 경우 반환되는 시퀀스에서 해당 요소를 제거할 IEnumerable<T>입니다.An IEnumerable<T> whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

Public Class Product
Public Property Name As String
Public Property Code As Integer
End Class
' Custom comparer for the Product class
Public Class ProductComparer
Implements IEqualityComparer(Of Product)
Public Function Equals1(
ByVal x As Product,
ByVal y As Product
) As Boolean Implements IEqualityComparer(Of Product).Equals
' Check whether the compared objects reference the same data.
If x Is y Then Return True
'Check whether any of the compared objects is null.
If x Is Nothing OrElse y Is Nothing Then Return False
' Check whether the products' properties are equal.
Return (x.Code = y.Code) AndAlso (x.Name = y.Name)
End Function
Public Function GetHashCode1(
ByVal product As Product
) As Integer Implements IEqualityComparer(Of Product).GetHashCode
' Check whether the object is null.
If product Is Nothing Then Return 0
' Get hash code for the Name field if it is not null.
Dim hashProductName =
If(product.Name Is Nothing, 0, product.Name.GetHashCode())
' Get hash code for the Code field.
Dim hashProductCode = product.Code.GetHashCode()
' Calculate the hash code for the product.
Return hashProductName Xor hashProductCode
End Function
End Class

이 비교자를 구현한 후에는 다음 예제와 같이 Except 메서드에서 Product 개체의 시퀀스를 사용할 수 있습니다.After you implement this comparer, you can use sequences of Product objects in the Except method, as shown in the following example: