Home > DeveloperSection > Blogs > Difference between IList and List in C#

Difference between IList and List in C#


.NET C#  Collection 
Ratings:
0 Comment(s)
 1585  View(s)
Rate this:

Difference between IList and List in C#

In this blog, I’m explaining about IList and List in C#

IList: It is non-generic collection object that can be individually access by index. The IList interface implemented from two interfaces and they are ICollection and IEnumerable.

Example:

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace IListExample

{

    class Program

    {

        static void Main(string[] args)

        {

            IList ilst = new string[3];

            ilst.Add("Sita");

            ilst.Add("Geeta");

            foreach (string num in ilst)

                Console.WriteLine(num);

 

            Console.ReadKey();

        }

    }

}

 

List: A list is a strongly typed list of object that can be accessed by index. It can be founder under System.collection.Generic namespace.

Example:

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace IListExample

{

    class Program

    {

        static void Main(string[] args)

        {

            IList<string> ilst = new List<string>();

            ilst.Add("Sita");

            ilst.Add("Geeta");

            foreach (string num in ilst)

                Console.WriteLine(num);

            Console.ReadKey();

        }

    }

}

 

Output:

Sita

Geeta


Don't want to miss updates? Please click the below button!

Follow MindStick