Q:

C# program to demonstrate the IDictionary interface

0

C# program to demonstrate the IDictionary interface

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

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)
    {
        Console.WriteLine(i["Name"]);
    }

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

        Student["Name"] = "Virat";
        PrintDictionry(Student);

        Student["Name"] = "Rohit";
        PrintDictionry(Student);

        Employee["Name"] = "Saurabh";
        PrintDictionry(Employee);

        Employee["Name"] = "Sachin";
        PrintDictionry(Employee);
    }
}

Output:

Virat
Rohit
Saurabh
Sachin
Press any key to continue . . .

Explanation:

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the static class... >>
<< C# program to demonstrate the IList interface...