Labels

slider

Recent

Navigation

Comparing IEnumerable and IList in C#: Choosing the Right Collection Interface

Discover the key differences between IEnumerable and IList in C#
Comparing IEnumerable and IList in C#

Intoduction

Hi readers! Hope you have gone through my previous articles on SQL stored procedure and web applications and now we will have a focus on difference between IEnumerable and IList.

IEnumerable VS IList

In LINQ to query information from gatherings, we utilize IEnumerable and IList for data editing process. Generally, IEnumerable gets inherited by IList, hence it possesses all the characteristics of it and apart from this, it contains its own characteristics. IList has below benefits over IEnumerable.

ILIST

  1. IList is available in the Namespace: System.Collections.
  2. IList is valuable when you wish to Add or remove things from the list.
  3. IList can obtain the no. of elements in the list without disturbing the list.
  4. IList is utilized to obtain an element in a particular position/index in a given list.
  5. Unlike IEnumerable, IList is also considered to be best to retrieve information from in-memory groupings like List, Array etc.
  6. IList allows deferred data interaction.
  7. IList doesn't allow next filtering.

IEnumerable

  1. IEnumerable is available in Namespace: System.Collections.
  2. IEnumerable can proceed ahead only over a group, it is unable to move backward and also, unable to move between the items.
  3. Through IEnumerable we can obtain the no of elements in the group after iterating the data collection.
  4. IEnumerable is preferred to retrieve data from in-memory grouping such as List, Array etc.
  5. IEnumerable never allows adding or removing items from the list.
  6. IEnumerable allows deferred result.
  7. IEnumerable allows next filtering.

Summary

Hope you must have a better idea about the difference between IEnumerable and IList. I hope after reading the above content you will be able to improve your LINQ query output. You can decide now which one you should use and what will be output.

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

0 comments: