urmila gupta
what is the difference between IList and IEnumerable
By urmila gupta in C# on Sep 13 2012
  • Narayan Pramar
    Jan, 2013 5

    IEnumerable provides only minimal "iterable" functionality. You can traverse the sequence, but that's about it. This has disadvantages -->> for example, it is very inefficient to count elements using IEnumerable, or to get the nth element -->> but it has advantages too -->> for example, an IEnumerable could be an endless sequence, like the sequence of primes.IList is an interface which abstracts list functionality (count, add, remove, indexer access) away from the various concrete classes such as List, BindingList, ObservableCollection, etc.

    • 0
  • Narayan Pramar
    Jan, 2013 5

    IEnumerable provides only minimal "iterable" functionality. You can traverse the sequence, but that's about it. This has disadvantages -->> for example, it is very inefficient to count elements using IEnumerable, or to get the nth element -->> but it has advantages too -->> for example, an IEnumerable could be an endless sequence, like the sequence of primes.IList is an interface which abstracts list functionality (count, add, remove, indexer access) away from the various concrete classes such as List, BindingList, ObservableCollection, etc.

    • 0
  • Narayan Pramar
    Jan, 2013 5

    IEnumerable provides only minimal "iterable" functionality. You can traverse the sequence, but that's about it. This has disadvantages -->> for example, it is very inefficient to count elements using IEnumerable, or to get the nth element -->> but it has advantages too -->> for example, an IEnumerable could be an endless sequence, like the sequence of primes.IList is an interface which abstracts list functionality (count, add, remove, indexer access) away from the various concrete classes such as List, BindingList, ObservableCollection, etc.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • shaik azhar
    Sep, 2012 20

    IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • nimesh singh
    Sep, 2012 18

    There is a major difference.IEnumerable is an open set. If you research the "yield" statement you'll find that calling "ToList()" is only one way to populate an enumerable list. You can create enumerables on the fly and use the iterator state machine to continue to provide values.IList, on the other hand, is a finite set. The key difference is that IList provides a count so you have knowledge beforehand how large the list is.The purpose of enumerable is to take a very large set and enumerate over the set without actually having to load all of the values or elements in the set. The list on the other hands must account for all elements up front.In your example both situations work pretty much the same because you are casing to a list and then either exposing the list directly, or exposing the enumerator to the list.

    • 0
  • Pravin Patil
    Sep, 2012 14

    The simplest answer to this question is - IEnumerable allows only iteration on it's members(As in For...Each), while IList allows add/remove along with Iteration.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS