Sunday 27 April 2014

IEnumerable, ICollection, IList and List an Overview



Category
Methods
Name Space
Inherits from
Use
IEnumerable
GetEnumerator
System.Collections
 
Provided read-only access to elements in that collection via iteration.
IEnumerable<T> (Type safe version)
GetEnumerator
System.Collections.Generic
IEnumerable
ICollection
1.      Defines size, enumerators
2.      Asynchronization methods for all nongeneric collections.
System.Collections.ICollection
Modify the collection and care about its size.
ICollection<T>
Defines methods to manipulate generic collections.
System.Collections.Generic.ICollection
IEnumerable<T>
IList
1.      Adding/  removing elements
2.      Clear the collection.
3.      Handle  positioning of the elements
4.      Provides an object indexer to allow the user to access the collection
 eg myList[elementIndex]
 
ICollection
Modify the collection and ordering and / or positioning of the elements in the collection.
 
IList<T>
Some new methods for accessing a collection with specific positioning are present.
ICollection<T>
List
Dynamically resize arrays
 
IList
Ideal for linear collections not accessed by keys
List<T>
1.      Add  items
2.      Use an equality comparer
3.      accepts null as a valid value for reference types  
4.      Allows duplicate elements.
5.      Type safe than ArrayList
Never have own member implementations with the concrete type List/List<T>.

No comments:

Post a Comment