Reputation: 3126
Why is there a Distinct() method available on the HashSet when they cannot contain duplicates anyway?
Upvotes: 6
Views: 1328
Reputation: 64467
The Distinct
method is not on the HashSet<>
, but the IEnumerable<>
that is implemented by the HashSet<>
.
Extension methods cannot be "omitted" from certain types. Once added to a type, all of that type and any derived will get the extension method.
Just to demonstrate, if you extended object
you'd litter everything if you added the relevant namespace. So don't go adding:
namespace System
{
public static class ObjectExtensions
{
public static void Garbage(this object foo)
{
}
}
}
Upvotes: 13