Collection Interfaces and Types C# Help

Collection classes can be grouped into collections that store elements of type Object and generic collection classes. Previous to CLR 2.0, generics didn’t exist. Now the generic collection classes usually are the preferred type’ of collection. Generic collection classes are type-safe, and there is no boxing if value types are used. You need object-based collection classes only if you want to add objects of different types where the types are not based on each other, for example, adding int and string objects to one collection. Another group of collection classes is collections specialized for a specific type; for example, the StringCollection class is specialized for the string type.

Object type collections are located in the namespace System.Collections generic collection classes are located in the namespace System. Collections .Generic. Collection classes that are specialized for a specific type are located in the namespace System. Collections. Specialized. Of course, there are also other ways to group collection classes. Collections can be grouped into lists, collections, and dictionaries based on the interfaces that are implemented by the collection class. Interfaces and their functionalities are described in the following table..NET 2.0 added new generic interfaces for collection classes, for example, IEnurnerable<T> and IList<T>. Whereas the non-generic versions of these interfaces define an Object as a parameter of the methods, the generic versions of these interfaces use the generic type T.

The following table describes interfaces implemented by collections and lists, and their methods and properties.

Capture

Capture1

Capture

The non-generic interface ICollection defines properties used to synchronize different threads accessing the same collection. These properties are no longer available with the new generic interfaces. The reason for this change was that these properties led to a false safety regarding synchronization, because the collection usually is not the only thing that must be synchronized. You can rtIId information about synchronization with collections.

The following table lists the collection classes and the collection interfaces that are implemented by these classes:

Capture

Posted on October 29, 2015 in Collections

Share the Story

Back to Top