Reading the accepted answer of C# Java HashMap equivalent, it literary states:
C#'s Dictionary uses the Item property for setting/getting items:
- myDictionary.Item[key] = value
- MyObject value = myDictionary.Item[key]
And when trying to implement it, I get an error when using:
myDictionary.Item[SomeKey] = SomeValue;
Error: CS1061 'Dictionary' does not contain a definition for 'Item'
And I will need to use a myDictionary.Add(SomeKey, SomeValue);
instead same as this answer and MSDN - Dictionary in order to resolve the error.
The code is fine, but out of curiosity am I doing anything wrong? Other than one does not compile, what is the difference between
Dictionary.Item[SomeKey] = SomeValue;
and
Dictionary.Add(SomeKey, SomeValue);
Edit:
I edited the accepted answer in C# Java HashMap equivalent. See edition history to know why.