I need to design my own custom GenericCollection class. Now i have plenty of options to derive it using IEnumerable, ICollection, and IList, where later offers some added functionalities.
I am little confused that if i go with IEnumerable<T> i might require declaring the object to actually hold the collection like in this case _list.
public class GenericCollection<T> : IEnumerable<T>
{
private List<T> _list;
//...
}
But if i go with ICollection<T> or IList<T>, i do not require to declare the List object as it is implicitly available.
public class GenericCollection<T> : IList<T>
{
// no need for List object
//private List<T> _list;
//...
}
What is the difference between these two approaches with respect to performance?
In which scenario each one is preferred especially when it comes to designing your own collection. I am interested in the light weight collection with good performance. I think this can be achieved using IEnumerable<T> but how exactly along with some strong reasons to go with it?
I have reviewed some existing posts but none is giving required information.