Quick question which I fear has a short and disappointing answer but alas I shall ask anyway.. In the C++ Dictionary method TryGetValue() is there any way to change the defaul开发者_运维知识库t value that will be returned for an integer (to -1 instead for example) when the key is not present? The problem is that 0 is the default and this is not suitable because a value of 0 would make sense in the context of my program.
If not, is the ContainsKey() method that much slower? Or is it splitting hairs and nothing to worry about seeing as in all likelihood I have no choice..
Many thanks
PS I don't need to perform any hashing function (though this might be in the implementation for Dictionary anyway!), nor have any particular ordering to my collection, I just want lookup and adding to be as fast as possible. Is Dictionary a sound choice?
Why don't you create a class that inherits from Dictionary(Of TKey, TValue)
and override the TryGetValue
function. You could then use your own class and it would behave just as you would want it to...
精彩评论