Mid
From PDF
Collections
C# Collections
What happens when you try to insert a duplicate key into a Dictionary?
- Using Add() will throw a System.ArgumentException
- Using the indexer (dictionary[key] = value) will overwrite the existing value
Example:
dictionary.Add("John", 25);
dictionary.Add("John", 30); // Exception
dictionary["John"] = 30; // Overwrites the value safelyShare this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png