.NET 4.x SortedDictionary, ContainsKey(0). Исключение "The given key was not present in the dictionary" - C#
Формулировка задачи:
Выбрасывается исключение "The given key was not present in the dictionary." при попытке проверить, есть ли в словаре ключ 0. Почему?
Код:
P. S. Проверку ключа вынес во внутренний if, чтобы не было исключения, но интересует причина ошибки.
if (_array[i] != 0 && !dictionary.ContainsKey(_array[i]))
dictionary.Add(_array[i], 1);Решение задачи: «.NET 4.x SortedDictionary, ContainsKey(0). Исключение "The given key was not present in the dictionary"»
textual
Листинг программы
for (int i = 0; i < _array.Length; i++)
if (_array[i] != 0 && !dictionary.ContainsKey(_array[i]))
{
k = _arrayDegrees[i];
try
{
local_DegreesCounts.Add(_arrayDegrees[i], 1); // Add degree
}
catch (Exception ex)
{
MessageBox.Show(dictionary.ContainsKey(_array[i]));
}
}