What is the difference between List and Collection. Where and under what conditions would it be more rational to use this or that type?

    1 answer 1

    The difference is that in Collection<T> there are a number of virtual methods ( InsertItem , RemoveItem , SetItem , ClearItems ), which you can override in the class that ClearItems at your discretion, and thus set these inheritors their behavior when inserting, deleting or clearing items. In this case, the List<T> class focuses more on speed when performing insert / delete / cleanup operations, rather than providing the user with extensibility tools in heir classes (he has no virtual members at all).

    MSDN authoritatively states that

    Provides the base class for a generic collection

    In other words, the Collection<T> class is primarily intended to create its own generalized collections on its basis, while List<T> "for work"

    • one
      thanks for the answer. Briefly and in the case. - khirnick