Dictionary KeyNotFoundException even though Key exists

前端 未结 3 1032
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 07:39

I have a RegistryKey as a Key for my dictionary.

I cannot seem to set a value for that specific Key. Whatever I do, I keep getting a KeyNotFoundE

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 08:17

    CreateSubKey presumably returns a new object instance each time you call it. As such, calling it twice will give you different objects (even though they may refer to the same registry key). You should store the result of the first call to CreateSubKey instead of calling it again. Or use the key name instead of an object as your dictionary's key.

提交回复
热议问题