I am using a Dictionary with key , value as of type string
var dictionary = new Dictionary<string, string>();
dictionary.Add("cat",null);
dictionary.Add("dog", "vals");
dictionary.Add("Tiger", "s");
There is a custom enum class like this exists
public enum AnimalName
{
Cat = 0,
Dog = 1,
Rabit = 2,
Tiger = 3,
Lion = 4
}
There is a permitted list of values from this enum available
AnimalName[] permitted_list = {
AnimalName.Cat,
AnimalName.Dog,
AnimalName.Rabit
};
How can we check the dictionary contains atleast one key from the array permitted_list , with a not null value
I used this code to check atleast one not null value exists in the dictionary
//CHECK atleast one not null value exists
bool canProceed=dictionary.Any(e => !string.IsNullOrWhiteSpace(e.Value));
Can we extend this to check for the existence of dictionary Key from the list of enums
//Example in this case key Dog exists with a not null value So canProceed is TRUE
//in this case#2 canProceed is FALSE , since the only permitted_list key is Cat and its value is NULL
var dictionaryf = new Dictionary<string, string>();
dictionaryf.Add("cat",null);
dictionaryf.Add("Tiger", "s");
dictionaryf.Add("Lion", "exit sjs");
permitted_list .Select(x => $"{x}".ToLower()) .Any(x => dictionary.TryGetValue(x, out string value) && value != null);