Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
Which is better and fast IQueryable or List
Posted
Comments
Maciej Los 12-Dec-14 5:51am    
In what aspect?
[EDIT]
Please, provide more details...
At this moment the question makes no sense. There is no comparable area between IQuerable and List. There is nothing in common.

1 solution

You're asking about two structures that do completely different things. A List<> is a robust collection that supports inserts as well as a few other utility functions that make it more robust than []. There is an excellent primer on enumerable types at:
List vs IEnumerable vs IQueryable vs ICollection vs IDictionary[^]

IQueryable is designed to be a Lazy<> wrapper that will provide a hook to a filtered IEnumerable, not the IEnuerable itself. This is useful for high-overhead situations (large lsists, slow data access, etc) where loading ALL data upfront is un-needed and will negatively impact application perfomance. IQueryable is used extensively in the entity Framework because it represents data that resides on a SQL database, and you may perform several filtering and sorting operations before a call is made to actually pull the data down. An IQueryable is not an IEnumerable(really) until GetEnumerator is called on it, at which point it will pull down that data that it is acting as a proxy for.

To be concise in an answer though: Unless you are dealing with a library that is designed to use IQuerable, use a List for a collection that you will be manipulating, and use [] for a list of items that just need to be read.
 
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