blog

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

Difference between IList and List in C#

priyanka kushwaha21543 09-Mar-2015

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

IList: It is non-generic collection object that can be individually accessed 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

{

    classProgram

    {

        staticvoid Main(string[] args)

        {

            IList ilst = newstring[3];

            ilst.Add("Sita");

            ilst.Add("Geeta");

            foreach (string num in ilst)

                Console.WriteLine(num);

 

            Console.ReadKey();

        }

    }

}

 Difference between IList and List in C#


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

{

    classProgram

    {

        staticvoid Main(string[] args)

        {

            IList<string> ilst = newList<string>();

            ilst.Add("Sita");

            ilst.Add("Geeta");

            foreach (string num in ilst)

                Console.WriteLine(num);

            Console.ReadKey();

        }

    }

}

 

Output:

Sita

Geeta


Updated 22-Feb-2018

Leave Comment

Comments

Liked By