I tried checking for null but the compiler warns that this condition will never occur. What should I be looking for?
Consider the option of encapsulating this particular dictionary and provide a method to return the value for that key:
public static class NumbersAdapter
{
private static readonly Dictionary Mapping = new Dictionary
{
["1"] = "One",
["2"] = "Two",
["3"] = "Three"
};
public static string GetValue(string key)
{
return Mapping.ContainsKey(key) ? Mapping[key] : key;
}
}
Then you can manage the behaviour of this dictionary.
For example here: if the dictionary doesn't have the key, it returns key that you pass by parameter.