I would like to be able to compare multiple strings with each other and return true if they are all equal. If any of the strings equal “N/A” then they are to be ignored in the comparison. For example:
string1 = "hi";
string2 = "hi";
string3 = "hi";
string4 = "N/A";
would return true, but:
string1 = "hi";
string2 = "hey";
string3 = "hi";
string4 = "hi";
would return false.
Thanks for your help.
Assuming that you’ve stored the strings in a colllection like array or list, you can use
Enumerable.All:Explanation: you can compare all strings with one of your choice(i take the first), if one is different
allEqualmust be false. I need to useFirstOrDefaultsince it’s possible that all strings are “N/A” or the list is empty, thenFirstwould throw an exception.DEMO