This program uses Dictionary and SortedDictionary. Suppose that you want to add some functionality that can work on an instance of Dictionary or an instance of SortedDictionary.
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Dictionary implements IDictionary.
Dictionary<string, string> dict = new Dictionary<string, string>();
dict[
"A"] =
"B";
WriteKeyA(dict);
// SortedDictionary implements IDictionary.
SortedDictionary<string, string> sort = new SortedDictionary<string, string>();
sort[
"A"] =
"C";
WriteKeyA(sort);
}
static void WriteKeyA(IDictionary<string, string> i)
{
// Use instance through IDictionary interface.
Console.WriteLine(i[
"A"]);
}
}
B
C