IEnumerable <> => Allows the use of 'foreach' in a collection
ICollection <> => Since IEnumerable <> + Add (), Remove (), Count, Clear (), Contains (), IsReadOnly, CopyTo ()
IList <> => Like ICollection <> + this [int], Insert (), IndexOf (), RemoveAt (). i.e. It adds an index type to list operators
• May use 'return yield ???' combined with IEnumerable <> to return only one object at a time. Here comes the real power of IEnumerable (and not just the return of a list or array).
• When returning the list, decide what can be exposed to the user and return the appropriate type.
• Perhaps it is best to return ICollection <> or IList <>, and if the code client only needs to list the list, it can pass it to IEnumerable <>. i.e. Given ICollection SomeMethod () ... The user can call it as IEnumerable widgets = SomeMethod ()
Varun Gupta Jun 19 '12 at 8:30 2012-06-19 08:30
source share