Why collections in c
It eliminates duplicate elements. However, there is no need to specify the size of the ArrayList like with an array as it grows automatically.
SortedList SortedList stores key and value pairs. It automatically arranges elements in ascending order of key by default. C includes both, generic and non-generic SortedList collection. C includes both, generic and non-generic Stack. C includes generic and non-generic Queue. Hashtable Hashtable stores key and value pairs. It retrieves the values by comparing the hash value of the keys.
Each type of collection is designed for a specific purpose. Generic classes. Concurrent classes. Collections classes. You can create a generic collection by using one of the classes in the System. A generic collection is useful when every item in the collection has the same data type.
A generic collection enforces strong typing by allowing only the desired data type to be added. The following table lists some of the frequently used classes of the System. Generic namespace:. NET Framework 4 and later versions, the collections in the System. Concurrent namespace provide efficient thread-safe operations for accessing collection items from multiple threads.
The classes in the System. Concurrent namespace should be used instead of the corresponding types in the System. Collections namespaces whenever multiple threads are accessing the collection concurrently. For more information, see Thread-Safe Collections and System. Some classes included in the System. Collections namespace do not store elements as specifically typed objects, but as objects of type Object. Whenever possible, you should use the generic collections in the System. Generic namespace or the System.
Concurrent namespace instead of the legacy types in the System. Collections namespace. The following table lists some of the frequently used classes in the System. Collections namespace:. The System. Specialized namespace provides specialized and strongly typed collection classes, such as string-only collections and linked-list and hybrid dictionaries. Generic namespace. Following are the different type of generic collection classes which are provided by System. In c , concurrent collections are useful to access collection items from multiple threads, and these are available from.
NET Framework 4 with System. Concurrent namespace. If we are using multiple threads to access a collection concurrently, then we need to use concurrent collections instead of non-generic and generic collections.
Following are the different type of concurrent collection classes which are provided by System. Collections in C. Types of collections C collections are categorized into 3 main namespaces: System.
Generic classes Generic System. Concurrent classes Concurrent System. Collections classes Non-Generic To add elements to a collection, we declare an instance of a class.
Generic classes Generic In case the elements are of the same data type, we use one of the classes in the System. Concurrent classes Concurrent Concurrent collections are supported in the. Collections classes Non-Generic Unlike the generic collection, non-generic collections accept elements of different data types and utilize the System.
Add ; data. Add 23 ; data. Add new OurArrayList ; data. ArrayList OurArrayList. Remove 23 ;. Push 4 ; myStk. Push 3 ; myStk. Push 6 ; myStk. Push 4 ; Console. WriteLine myStk.
0コメント