Q:

C# program to demonstrate the IList interface

0

C# program to demonstrate the IList 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 IList interface is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the IList interface
 
using System;
using System.Collections.Generic;

class Demo
{
    static void Print(IList<string> list)
    {
        foreach (string str in list)
        {
            Console.WriteLine("\t"+str);
        }
    }
    static void Main()
    {
        string[] countries = {"India","China","Russia","USA"};
        List<string> studntents = new List<string>();

        studntents.Add("Rohit");
        studntents.Add("Shikhar");
        studntents.Add("Virat");

        Console.WriteLine("Countries: ");
        Print(countries);

        Console.WriteLine("Students: ");
        Print(studntents);
    }
}

Output:

Countries:
        India
        China
        Russia
        USA
Students:
        Rohit
        Shikhar
        Virat
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 strings in the IList interface and then print the items on the console screen.

Now look to the Main() method, Here we created the array of strings that contains the strings. After that, we created a list using the List collection class that contains name students, and then we printed the name of countries and students using the Print() method 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 IDictionary interfac... >>
<< C# program to demonstrate the properties in the in...