Returning a default value. (C#)

后端 未结 3 1300
盖世英雄少女心
盖世英雄少女心 2020-12-03 14:42

I\'m creating my own dictionary and I am having trouble implementing the TryGetValue function. When the key isn\'t found, I don\'t have anything to assign to the out parame

3条回答
  •  难免孤独
    2020-12-03 14:58

    You are looking for the default keyword.

    For example, in the example you gave, you want something like:

    class MyEmptyDictionary : IDictionary
    {
        bool IDictionary.TryGetValue (K key, out V value)
        {
            value = default(V);
            return false;
        }
    
        ....
    
    }
    

提交回复
热议问题