KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have method with HashSet parameter. And I need to do case-insensitive Contains within it: public void DoSomething(HashSet<string> set, string item) { var x = set.Contains(item); ... } Is it any way to make existing HashSet case-insensitive (do not create new one)? I'm looking for solution with best perfomance. Edit Contains can be called multiple times. So IEnumerable extensions are not acceptable for me due to lower perfomance than native HashSet Contains method. Solution Since, answer to my question is NO, it is impossible, I've created and used following method: public HashSet<string> EnsureCaseInsensitive(HashSet<string> set) { return set.Comparer == StringComparer.OrdinalIgnoreCase ? set : new HashSet<string>(set, StringComparer.OrdinalIgnoreCase); }
Tags (comma-separated)
Save Edits
Cancel