HashSet.UnionWith documentation FAIL – trust your instinct

   edit
Follow


From the method’s doc:

Modifies the current HashSet<T> object to contain all elements that are present in both itself and in the specified collection.

 

image

 

Now I know my way around (at least the basics of) set theory, and I know what union means. nonetheless I read the doc of the method and for some reason I thought that I’d get the intersection.

 

For those unsure about what Union means (or what it actually does), the following code:

var set = new HashSet&lt;int&gt;(new[] {1, 2});
var other = new[] {2, 3};
set.UnionWith(other);
Console.WriteLine(Serialize(set));

 

So, I ended up bumping my head on the wall keyboard for a couple of minutes trying to understand why a perfectly good test fail with no reason, until I figured it out. It is true that I wasn’t showing a huge amount of smartness here, and it could be that my English skills are poor, but I believe replacing “and” with “or” will serve the method’s doc better.

 

If the BCL was open source I would have sent a patch with the doc fix …


     Tweet Follow @kenegozi