C# Difference between List and IList

Can you please  tell me the  difference between

List and ILlsit in C#
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IList is interface for collection of objects that can be individually accessed by index.

public interface IList : ICollection, IEnumerable
    // Methods
    int Add(object value);
    void Clear();
    bool Contains(object value);
    int IndexOf(object value);
    void Insert(int index, object value);
    void Remove(object value);
    void RemoveAt(int index);

    // Properties
    bool IsFixedSize { get; }
    bool IsReadOnly { get; }
    object this[int index] { get; set; }

Many collection classes implement IList interface: List<T>, ArrayList, Array, TreeNodeCollection etc
So, List<T> is just implementation of generic version of IList interface and some other interfaces.

public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
 // Implementation goes here.
IList is an interface. You can't instantiate an object from it. See: http://msdn.microsoft.com/en-us/library/87d83y5b%28VS.80%29.aspx

List is an object. You can instantiate an object from it.

IList and List can be used as polymorphism. IList<string> myList = new List<string>(); See: http://msdn.microsoft.com/en-us/library/ms173152%28VS.80%29.aspx

Shahan AyyubSenior Software EngineerCommented:
List is an object we can instantiate it. Also List<T> is also available that can instantiate an object of your mention datatypes.

While IList is an interface,we implements its methods & properties in our classes.

As mention by lazyberezovsky(In first example)  some signatures are provided in example. We implements such kinds of signatures in our classes by the help of inheritance.

Moreover IList is inheritance by ICollection & IEnumerable



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.