I am trying to loop through a list of strings and check them against a single string. If nothing is found that matches then we need to exit the code.
// loadedObj.Settings contains the list of strings, can be any number of strings
foreach (var currentCheckBox in loadedObj.Settings.Where(currentCheckBox => currentCheckBox != null))
{
// docTypeAlias is a single string that needs to be matched
var docTypeAlias = sender.ContentType.Alias;
// This is the current value of currentCheckBox
var requiredTypeAlias = currentCheckBox;
if (!requiredTypeAlias.Equals(docTypeAlias)) return;
}
The code works fine if there is only 1 string in Settings, but as soon as you have multiple strings, if the first one doesn’t match obviously the code exits too soon.
You can use
Anyto see if any element in the sequence matches your criteria. If none do, the result will be false.