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
You are looking for the default keyword.
For example, in the example you gave, you want something like:
class MyEmptyDictionary<K, V> : IDictionary<K, V>
{
bool IDictionary<K, V>.TryGetValue (K key, out V value)
{
value = default(V);
return false;
}
....
}
default(T)
return default(int);
return default(bool);
return default(MyObject);
so in your case you would write:
class MyEmptyDictionary<K, V> : IDictionary<K, V>
{
bool IDictionary<K, V>.TryGetValue (K key, out V value)
{
... get your value ...
if (notFound) {
value = default(V);
return false;
}
}
....
}