Compare two hashes?
I have two hashes, for example:
HashSet<string> log1 = new HashSet<string>(File.ReadLines("log1.txt"));
HashSet<string> log2 = searcher(term);
How would I compare the two?
I want to make sure that it log2does not contain entries from log1. In other words, I want to remove all (if any) elements that log1have inside log2.
+5
3 answers
To remove all elements from log2that are in log1, you can use the HashSet <T> .ExceptWith Method :
log2.ExceptWith(log1);
Alternatively, you can create a new HashSet <T> without changing the two original sets using the Enumerable.Except Extension Method :
HashSet<string> log3 = new HashSet<string>(log2.Except(log1));
+14