Is there a more concise way to check if x is either “a”,”b”,”c”,”d” or “e”?
if (x == "a" | x == "b" | x == "c" | x == "d" | x == "e"){//do something}
Basically I want to know if I can express the same if statement without repeating the variable name x.
How about:
You can consider using a
HashSet<string>or similar and caching a reference to it in a field for improved performance (to give you anO(1)Contains operation and to avoid allocating, populating the collection).