![]() |
In C# IList interface is an interface that belongs to the collection module where we can access each element by index. Or we can say that it is a collection of objects that are used to access each element individually with the help of an index. It is of both generic and non-generic types. Its implementation is generally categorized into three parts that are:
Syntax: // For Non_generic IList public interface IList : System.Collections.ICollection // For Generic IList public interface IList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T> Properties: Some of the commonly used properties of the IList interface are:
Methods: Some of the commonly used methods of the IList interface are:
Now we understand the working of IList interface with the help of an example. In the below example, we create a list with subjects and students and display the list. So to do this we have to follow the following approach: Approach: 1. Create an array of subjects {"os","cn","php","c/cpp","java/jsp","python/r"} 2. Create a list of student names and add names into it using Add() method. List<string> data = new List<string>(); data.Add("sai"); data.Add("sravan"); data.Add("jyothika"); 3. Define an IList Interface to display the students and subjects names. static void Show(IList<string> list) { // Iterate through list foreach (string str in list) { // Print Console.WriteLine("\t" + str); } } 4. Call the Show() method to display the list of students and subjects. Show(subjects); Show(data); Example: C#
Output: Subjects Name: OS CN PHP C/CPP Java/Jsp Python/R Students Name: sai sravan jyothika |
Reffered: https://www.geeksforgeeks.org
C# |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |