Home  /  Questions  /  Question

108   96.7
Jun 11, 2012

Difference between IList and List

I already Googled the difference between List and IList and it still is not that clear to me.
In the Patterns in Action dofactory project, the List are used in Business and Data layer but when they map it in the service layer the send it back as IList.

What are teh benefits of mapping it to an IList?
Could I simply send back a List and the application would function the same?

Thanks a lot.

377   99.9
Jun 14, 2012
Program to interface not to class.
IList is an interface and List is concrete class. 
Let's suppose you have a business object where you want to use a object of type Apple. May be it is fine for now but later you may need to support Mango type object. In that case you may probably need to change the business layer. 
To get rid of these tight coupling you need to use interface like IFruit. Then your business layer will not depend just on Apple class and you will get rid of tight coupling. 
 1 comment
Correct ! --- Tarriq Ferrose Khan  Jun 21, 2012

Sep 29, 2016
IList is an interface.  List is one concrete type that implements the IList interface. Other objects that implement IList are bound to share the same behaviour. If you plan to expose the interface to other callers that you currently know nothing about, or even vaguely consider that changing the list type to another is possible, say to a custom List type that implements IList, implement the interface instead of a concrete type. Check this article to know more details.

Difference between IList and List inC#


50   50
Aug 08, 2012
To understand the difference between List and IList you need to understand the difference between classes and interfaces.
It's the basic of OO development. You should first learn this before you continue on Design Patterns.