Demonstrate the iList Interface in C# – Programming, Pseudocode Example, C# Programming Example

Demonstrate the iList Interface in C#

This program defines a method Display that takes an IList<int> (an interface for a list of integers) as its parameter. The Main method creates an array of integers and a List<int> object, and it calls the Display method with each of these objects as its argument.

The Display method uses the Count property of the IList<int> interface to print the number of elements in the list, and it uses a foreach loop to iterate through the elements of the list and print each one.

The Main method first calls Display with an array of integers as its argument. Then it calls Display with a List<int> object as its argument. In both cases, the Display method is able to work with the parameter as if it were a list of integers, even though the actual type of the object being passed as an argument is different. This is an example of polymorphism, where a method can work with multiple types of objects in a similar way.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: