Back to list
Views:   36K
Replies:  3
Archived
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.
Dennis
Dennis Tucker, Jun 11, 2012
Reply 1
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#

BASIC DIFFERENCE BETWEEN ARRAYLIST AND LIST
Jonas Jonasstuart, Sep 29, 2016
Reply 2
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.
Wesley Walraeve, Aug 08, 2012
Reply 3
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. 
Pradip Shrestha, Jun 14, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas