Users Online

· Guests Online: 47

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate the iList Interface

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.

 

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

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.26 seconds
10,846,408 unique visits