This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3125|Reply: 1

[Source] .NET/C# implements the IEqualityComparer custom comparator

[Copy link]
Posted on 8/12/2023 7:41:38 PM | | | |
Requirements: If the objects in the collection are the same even though all the fields are the same, the custom comparator is mainly solvedDistinct、Except、IntersectThis requires the implementation of the IEqualityComparer interface to judge the equality of two objects.

The IEqualityComparer comparator calls the GetHashCode method by default, and then calls the Equals method to compare if the two objects are equal to GetHashCode.

For strings we also don't want to be case sensitive, the custom IEqualityComparer comparator is as follows:

The results are as follows:



There is also a scheme object that is directly implementedIEquatable<T> interface, rewrite the Equals and GetHashCode methods, the code is as follows:

The results are as follows:



(End)




Previous:SQL Server finds the data that varchar converts to bigint error
Next:Use PowerShell to generate the &lt;machineKey&gt; element
 Landlord| Posted on 10/2/2023 9:26:37 AM |
.NET/C# new feature record type
https://www.itsvse.com/thread-10673-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com