Closed
Description
Type of issue
Typo
Description
Current documentation for OrderedDictionary says that the Item[Object] property returns:
The value associated with the specified key. If the specified key is not found, attempting to get it returns null, and attempting to set it creates a new element using the specified key.
Actually, if you try to get the property and the key isn't found, it throws KeyNotFoundException.
Example code
OrderedDictionary<string,string> orderedDictionary = new();
if (orderedDictionary["test"] == null)
{
System.Console.WriteLine("Got null for key not in dictionary");
}
Expected result according to documentation:
Got null for key not in dictionary
Actual result:
Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'test' was not present in the dictionary.
at System.Collections.ThrowHelper.ThrowKeyNotFound[TKey](TKey key)
at System.Collections.Generic.OrderedDictionary`2.get_Item(TKey key)
at Program.<Main>$(String[] args) in D:\Example\Program.cs:line 4
Page URL
Content source URL
Document Version Independent Id
98d00605-bb79-4fd9-9187-97c3067602ed