C# program to demonstrate the IList interface

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

Here, we will demonstrate the IList interface with the help of the List collection class.

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.

C# Basic Programs »


ADVERTISEMENT
ADVERTISEMENT




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.