Add extension method to IDictionary - CSharp Custom Type

CSharp examples for Custom Type:Extension Methods

Description

Add extension method to IDictionary

Demo Code

using System;//w ww.java2 s .c o m
using System.ComponentModel;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public static class DictionaryExtensions
{
   public static void Add<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,TKey key, TValue value)
   {
      dictionary.Add(key, value);
   }
}
class MainClass
{
   static void Main()
   {
      var dictionary = new ConcurrentDictionary<string, int>
      {
         { "x", 10 },
         { "y", 20 }
      };
   }
}

Related Tutorials