I tried checking for null but the compiler warns that this condition will never occur. What should I be looking for?
You should check for Dictionary.ContainsKey(int key) before trying to pull out the value.
Dictionary myDictionary = new Dictionary();
myDictionary.Add(2,4);
myDictionary.Add(3,5);
int keyToFind = 7;
if(myDictionary.ContainsKey(keyToFind))
{
myValueLookup = myDictionay[keyToFind];
// do work...
}
else
{
// the key doesn't exist.
}