I have a datareader which has columns like this among other columns populated via an SP:
ColX ColY ColZ
NYC 100 200
NYC 101 200
EWR 100 200
EWR 100 200
I’m trying to iterate over this result, and perform an action like sending an email for every duplicate in the combination of ColX, ColY, ColZ; in the above example EWR-100-200
What is the efficient way to accomplish this given that I have no control over the SP that returns this data in C#?
Create a
Hashset<string>to hold keys for the items you’ve sent emails to. You can create the keys by:So:
The point here is that
keysUsed.Addwill returntrueif the item is added to theHashset. If the key already existed, the method would returnfalse.