What is the most basic class that inherits ICollection <T>
I need a generic collection class that I can add and list. Since ICollection<T> inherits from IEnumerable<T> , the class really just needs to inherit from ICollection<T> . Is there a simple generic class in BCL that simply inherits ICollection<T> as a generic version of CollectionBase? If not, which class is best suited?
I would suggest that List<T> is what I used, but I do not need a consistent aspect. Is there anything better (by which I mean [less memory / faster access / easier])? A bag would be perfect if it existed.
EDIT 1: In my particular case, I .concat connected to another IEnumerable, requesting it, and then displaying the results (in a specific order). I am not trying to make my own class. I just needed to make a multiple collection so many times that I thought it would be useful to find the best choice to use. Since I feel like I have done something like this many times, I felt that I should keep this question as general as possible (no pun intended), now I know better.
EDIT 2: Thanks for the answers. As @BlueRaja pointed out, any simple class will have the same overhead, and so I think I will stick to my original ways of using List<T> . Since they are all about the same, my stupid reasons are “easier to introduce” and “I shouldn't put another use into action” - not such bad reasons.
[less memory space / faster access / simpler]
All of them will have almost the same amount of memory, and if you use ICollection, the interface will not change.
What really matters is what will be best for the operations you need: Linked-list adds / removes better (head / tail elements), while an array-based list has random access. There are other structures that you should use, depending on your application.
You probably want to explore Collection<T> . It was designed for the explicit purpose of a subclass, as the documentation indicates:
Provides a base class for the general collection.
Having said that any of the collections is in order; I inherited from List<T> , Stack<T> and so on; Choose the one that is closest to the functionality you really need.
You can use Reflector to check .NET FCL and see which classes use this collection. (There is a search function that can be launched using F3.)
You can also look at the C5 Library to see if a collection has already been implemented that suits your needs. For a hierarchy of the collection interface, see page 13 of the C5 Manual .
CollectionBase existed primarily to provide a simple mechanism for creating typed collections. In Generics, all collections are now printed. The vast majority of cases where CollectionBase extensions were used should now use any built-in collections, such as List<> or LinkedList<> .
Collection<> still exists for those who need to provide a custom collection for reasons other than type (for example, an additional check for additions or some non-standard logic). Collection<> not as widely used as CollectionBase was and serves a much smaller need.