Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between HashSet.IsSuperSetOf and IsProperSuperSetOf?

Tags:

c#

hashset

MSDN documentation of both methods looks very similar. Also the example cited beneath the remarks for IsSupersetOf is not very helpful either.

Can someone please explain to me the difference using simple language?

like image 595
Klaus Nji Avatar asked Feb 24 '14 22:02

Klaus Nji


3 Answers

You can think of it like the difference between > and >=. IsSuperSetOf is doing something like >=, so your set could have exactly the same elements that are in the set you're comparing to. By contrast, a proper super set is kind of like > and has extra elements that the second set doesn't have.

For example, a set is a superset of itself, but it's not a proper superset of itself.

like image 89
Kyle Avatar answered Nov 12 '22 05:11

Kyle


A proper subset cannot equal the set.

{1,2,3} is a subset of {1,2,3}, but not a proper subset

{1,2} is a proper subset (and subset) of {1,2,3}

http://www.mathsisfun.com/sets/sets-introduction.html

like image 25
Justin Avatar answered Nov 12 '22 06:11

Justin


A superset of set A is a set that contains all of the elements of set A

A proper superset of A is a set that contains all of the elements of A but is not equal to A.

So if A = {1,2,3}, then {1,2,3} is a superset of A but not a proper superset, while {1,2,3,4} is a proper superset.

like image 9
D Stanley Avatar answered Nov 12 '22 05:11

D Stanley