Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Collections Vs System.Collections.ObjectModel

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?

like image 349
Manish Basantani Avatar asked Jun 25 '10 13:06

Manish Basantani


People also ask

What is the use of System collections generic?

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.

What is using System collections in C#?

Collections Namespace. Contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries.

What is ReadOnly collection?

ReadOnly collections prevents the modification of the collection which is defined with type ReadOnly.


1 Answers

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

like image 199
stuartd Avatar answered Sep 18 '22 17:09

stuartd