CSharp examples for Custom Type:Extension Methods
Add Extension Method to Dictionary
using System.Collections.Generic; using System.ComponentModel; static class PersonDictionaryExtensions { public static void Add(this Dictionary<string, Person> dictionary, Person person) {//from www .j ava 2s . c om dictionary.Add(person.Name, person); } } class SpecializedAddExtensionMethod { static void Main() { Dictionary<string, Person> dictionary = new Dictionary<string, Person> { { new Person { Name = "Jon" } }, { new Person { Name = "Holly" } } }; } } internal class Person { public string Name { get; set; } }