Best way to handle a KeyNotFoundException

后端 未结 6 1461
再見小時候
再見小時候 2021-01-31 01:26

I am using a dictionary to perform lookups for a program I am working on. I run a bunch of keys through the dictionary, and I expect some keys to not have a value. I catch the

6条回答
  •  暖寄归人
    2021-01-31 02:02

    you should use the 'ContainsKey(string key)' method of the Dictionary to check if a key exists. using exceptions for normal program flow is not considered a good practice.

提交回复
热议问题