This is a simple example of showing how you can see if two collections, especially hashsets, are equal in their elements.
Have you ever had the need to join elements from one collection to another? Or only show the unique elements from one collection to another? I’ve seen some creative ways of doing it. However using the built in UnionWith, SymmectricExceptWith, and ExceptWith methods can do these things.
.NET has the ability to compare two or more collection types to see what elements they have in common. The Intersect and IntersectWith methods. In this example I’ll be using these two methods along with the default string comparer and a custom string comparer.
Hash sets are one of the more unique collection types in the .NET framework. They work differently than a normal collection class such as a List. One of the main advantage of using a hashet is to avoid having duplicate elements in the collection. It’s internal use of standard Add, Remove, and Contains methods makes this one of the faster collection types to work with. Click more to see some examples I’ve provided.
For an brief explanation look at the summary comments in the Program.cs class.