Users Online

· Guests Online: 58

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate the iDictionary Interface

C# Program to Demonstrate the iDictionary Interface

 

This is a C# Program to demonstrate idictionary interface.

Problem Description

This C# Program Demonstrates iDictionary Interface.

Problem Solution

Here this program uses both the Dictionary and SortedDictionary types. Suppose that you want to add some functionality that can work on an instance of Dictionary or an instance of SortedDictionary.

Program/Source Code

Here is source code of the C# Program to Demonstrate iDictionary Interface. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 *  C# Program to Demonstrate iDictionary Interface
 */
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
       Dictionary<string, string> dict = new Dictionary<string, string>();
       dict["Tom"] = "Bob";
       WriteKeyA(dict);
       SortedDictionary<string, string> sort = new SortedDictionary<string, string>();
       sort["Tom"] = "Jerry";
       WriteKeyA(sort);
       Console.ReadLine();
    }
 
    static void WriteKeyA(IDictionary<string, string> i)
    {
 
       Console.WriteLine(i["Tom"]);
    }
}
Program Explanation

This C# program is used to demonstrate the IDictionary interface. This program uses both the Dictionary and SortedDictionary types. To add some functionality that can work on an instance of Dictionary or an instance of SortedDictionary.

 

It can be used in an elaborate implementation of a custom dictionary. It can also be used in simpler programs that act upon different dictionary types including Dictionary and SortedDictionary.
The Dictionary implements the IDictionary interface. SortedDictionary implements IDictionary. In Console.WriteLine(i[“Tom”]) by using instance through IDictionary interface.

Runtime Test Cases
 
Bob
Jerry

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.73 seconds
10,845,336 unique visits