from my past experience and stackoverflow, I learned that String.ToLower() is bad in performance. Now I have the following issue, I need to filter out or do a specific action when specific words are in a giant list.
Old approach, which I want to fix:
if (input.Any(i => i.ToLower() == "alle" || i.ToLower() == "all" || i.ToLower() == "none")
{
// do something
}
I was thinking of using a hashset, but I am questioning the performance and how it handles the case sensitivity, I basically dont care about the case sensitivity. Does it make sense for me to use the hashset?
my current suggestion as a solution:
var unwantedInputsSet = new HashSet<string> {"alle", "all", "none"};
if (input.Any(i => i => unwantedInputsSet.Contains(i)))
{
// do something
}
Is there any better alternative to this or not. Do you have any ideas how to approach this better?