C# program to demonstrate the IDictionary interface

Here, we are going to demonstrate the IDictionary interface in C#?
Submitted by Nidhi, on November 05, 2020

Here, we will demonstrate the IDictionary interface with the help of Dictionary and SortedDictionary collection class.


The source code to demonstrate the IDictionary interface is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the IDictionary interface

using System;
using System.Collections.Generic;

class Demo
    static void PrintDictionry(IDictionary<string, string> i)

    static void Main()
        Dictionary<string, string> Student = new Dictionary<string, string>();
        SortedDictionary<string, string> Employee = new SortedDictionary<string, string>();

        Student["Name"] = "Virat";

        Student["Name"] = "Rohit";

        Employee["Name"] = "Saurabh";

        Employee["Name"] = "Sachin";


Press any key to continue . . .


In the above program, we created a Demo class that contains two static methods Print() and Main(). In the Print() method, we receive an object that contains an IDictionary interface and then print the items based on the key on the console screen.

Now look to the Main() method, Here, we created the object of Dictionary and SortedDictionary class and then add items in the objects Student and Employee based on the Name key and then print them using the Print() method class on the console screen.

C# Basic Programs »


What's New (MCQs)

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.