C# Program to Demonstrate the iList Interface

This is a C# Program to demonstrate iList interface.

Problem Description

This C# Program Demonstrates iList Interface.

Problem Solution

Here Lists and arrays implement IList and this interface is an abstraction that allows list types to be used with through a single reference type. With it, we can create a single method to receive an int[] or a List.

Program/Source Code

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

/*
 *  C# Program to Demonstrate iList Interface
 */
using System;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        int[] a = new int[3];
        a[0] = 1;
        a[1] = 2;
        a[2] = 3;
        Display(a);
 
        List<int> list = new List<int>();
        list.Add(5);
        list.Add(7);
        list.Add(9);
        Display(list);
        Console.ReadLine();
    }
 
    static void Display(IList<int> list)
    {
        Console.WriteLine("Count: {0}", list.Count);
        foreach (int num in list)
        {
            Console.WriteLine(num);
        }
    }
}
Program Explanation

This C# Program is used to demonstrate iList Interface. Lists and arrays implement IList. This interface is an abstraction that allows list types to be used with through a single reference type with it. Create a single method to receive an int[] or a List<int> the Add(Object) adds an item to the IList.

advertisement
advertisement

Here the lists and arrays implements IList. This interface is an abstraction that allows list types to be used with through a single reference type. With it, we can create a single method to receive an int[] or a List.

Runtime Test Cases
 
Count: 3
1
2
3
Count: 3
5
7
9

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.