How to use HashSet<string>.Contains() method in case -insensitive mode?

Tasawer Khan picture Tasawer Khan · Apr 19, 2010 · Viewed 37k times · Source

How to use HashSet<string>.Contains() method in case -insensitive mode?

Answer

Jo&#227;o Angelo picture João Angelo · Apr 19, 2010

You can create the HashSet with a custom comparer:

HashSet<string> hs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

hs.Add("Hello");

Console.WriteLine(hs.Contains("HeLLo"));