T
tonci.tomic
I have IDictionary with integers as keys and values.
Suppose I want to set value for key=42 to 1 if entry doesn't exist in
container. Otherwise, I want to increment value. I ended with:
IDictionary dict;
....
dict.Add(42, 0); // does nothing if entry exist
int val = (int)dict[42];
++val;
dict[42] = val;
But it looks realy ugly. 3X slower than it should be. Any suggestions?
Suppose I want to set value for key=42 to 1 if entry doesn't exist in
container. Otherwise, I want to increment value. I ended with:
IDictionary dict;
....
dict.Add(42, 0); // does nothing if entry exist
int val = (int)dict[42];
++val;
dict[42] = val;
But it looks realy ugly. 3X slower than it should be. Any suggestions?