.ToSafeDictionary() extension method in csharp

added by DotNetKicks
8/19/2019 3:41:26 PM

2 Kicks, 238 Views

The .ToDictionary() extension will throw an argument exception if we have duplicate keys added to the dictionary. The above code throws the following exception System.ArgumentException: An item with the same key has already been added. In this post, we'll create an extension method which will ignore duplicate keys from being added to a dictionary.