I have two HashSets – setA and setB.
- How can we find the complement of setA and setB?
- Is the code for intersection the best way to find intersection?
CODE
string stringA = "A,B,A,A";
string stringB = "C,A,B,D";
HashSet<string> setA = new HashSet<string>(stringA.Split(',').Select(t => t.Trim()));
HashSet<string> setB = new HashSet<string>(stringB.Split(',').Select(t => t.Trim()));
//Intersection - Present in A and B
HashSet<string> intersectedSet = new HashSet<string>( setA.Intersect(setB));
//Complemenet - Present in A; but not present in B
UPDATE:
Use OrdianlIgnoreCase
for ignoring case sensitvity How to use HashSet<string>.Contains() method in case -insensitive mode?
REFERENCE: