Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can u tell me the difference between ilist and list ,where to use in the project
Posted

Before asking questions, please read this discussion:
How to ask a good question?[^]

Try simple search on google[^] with your question, you'll get About 95,800 results (0.20 seconds).

You can also try on MSDN:
List<t> Class[^]
IList Interface[^]

Moreover you can try CodeProject[^] similar answers.
 
Share this answer
 
Hi ,
List< T > is a specific implementation of IList< T >, which is a container that can be addressed the same way as a linear array T[] using an integer index. When you specify IList as the type of the method's argument, you only specify that you need certain capabilities of the container.

For example, the interface specification does not enforce a specific data structure to be used. The implementation of List< T > happens to the same performance for accessing, deleting and adding elements as a linear array. However, you could imagine an implementation that is backed by a linked list instead, for which adding elements to the end is cheaper (constant-time) but random-access much more expensive. (Note that the .NET LinkedList< T > does not implement IList< T >.)

This example also tells you that there may be situations when you need to specify the implementation, not the interface, in the argument list: In this example, whenever you require a particular access performance characteristic. This is usually guaranteed for a specific implementation of a container (List< T > documentation: "It implements the IList< T > generic interface using an array whose size is dynamically increased as required.").

Additionally, you might want to consider exposing the least functionality you need. For example. if you don't need to change the content of the list, you should probably consider using IEnumerable< T >, which IList< T> extends.
 
Share this answer
 
v2
IList will only expose the methods exposed by the interface IList
C#
IList<int> myList = new List<int>(); </int></int>

List will expose all members of the List object
C#
List<int> myList = new List<int>(); </int></int>


If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than concrete implementations. This will help if you decide to change the implementation of your class later to use a different concrete class. In that case the users of your library will not need to update their code since the interface does not change.
If you are just using it internally, you may not care so much, and using List<t>;</t> may be ok.

Look at below links for more information:
http://forums.asp.net/t/1775855.aspx/1[^]
http://forums.asp.net/t/1231995.aspx/1[^]
http://oreilly.com/catalog/pnetcomp2/chapter/ch03.pdf[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900