I tried checking for null but the compiler warns that this condition will never occur. What should I be looking for?
The Dictionary throws a KeyNotFound
exception in the event that the dictionary does not contain your key.
As suggested, ContainsKey
is the appropriate precaution. TryGetValue
is also effective.
This allows the dictionary to store a value of null more effectively. Without it behaving this way, checking for a null result from the [] operator would indicate either a null value OR the non-existance of the input key which is no good.