There seem to be certain collection classes in System.Collections.ObjectModel as well. What is the difference between the collections under these two namespaces and in which scenario should we use System.Collections.ObjectModel?
Collections. Generic Namespace. Contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
Collections Namespace. Contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries.
ReadOnly collections prevents the modification of the collection which is defined with type ReadOnly.
From MSDN:
The System.Collections.ObjectModel namespace contains classes that can be used as collections in the object model of a reusable library. Use these classes when properties or methods return collections.
See also The reason why Collection, ReadOnlyCollection, and KeyedCollection were moved to System.Collections.ObjectModel namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With