I try to use a Dictionary and need to Check if the Value of a Key (called Name) is empty and if so, then use some default string as Value for my Key as, something like "unknown".
I know I can check a string for example with string.Length == 0 but my problem here is that I have an object as value and its hard for me to catch it.
Thats my code:
IDictionary<string, object> parameters = new Dictionary<string, object>();
string Name = de.Properties["Name"].Value.ToString(); //Name is sometimes empty and sometimes not
parameters.Add("Name", Name);
Update:
IDictionary<string, object> parameters = new Dictionary<string, object>();
string Name = de.Properties["Name"].Value.ToString();
if (parameters.TryGetValue("Name", out var Name))
{
parameters.Add("Name", Name ?? "unknown");
}