5

C# Collection class had me pulling my hair out for hours the past two days.

With a list, you can do new List<T>(IEnumerable<T>) and it creates a new list with the contents of the parameter in it.

With new Collection<T>(ICollection<T>), however, the new object is a reference to the parameter passed in.

Is it just me, or does that seem fucking bonkers?

Comments
  • 1
    Those classes are made for different purposes.

    List is the class to use if you just want to use it to store things. It's capacity setting allows to preallocate memory so there isn't resizing required.

    Collection has less functionality and more parts virtual. It's in the System.Collections.ObjectModel because it's intended to be used as a base class for use in components.
  • 0
    @CWins I know why Collection exists; whether or not it's designed to be extensible has nothing to do with how its constructors should behave.
Add Comment