Is there an IDictionary implementation that, on missing key, returns the default value instead of throwing?

前端 未结 15 1850
暗喜
暗喜 2020-11-27 04:00

The indexer into Dictionary throws an exception if the key is missing. Is there an implementation of IDictionary that instead will return de

15条回答
  •  半阙折子戏
    2020-11-27 05:02

    Collections.Specialized.StringDictionary provides a non-exception result when looking up a missing key's value. It is also case-insensitive by default.

    Caveats

    It is only valid for its specialized uses, and — being designed before generics — it doesn't have a very good enumerator if you need to review the whole collection.

提交回复
热议问题