In visual basic, generic collections will enforce type safety so we can store only the elements which are having the same data type and these are provided by System.Collections.Generic namespace.
In the previous chapter, we learned about collections and these are useful to store elements of different data types but the problem with collections is while retrieving an elements we need to perform a typecasting (boxing and unboxing) and it will effect application performance so to solve this problem visual basic introduced a generic collections with System.Collections.Generic namespace.
In visual basic, generic collections are the strongly-typed objects so it will allow only same data type elements to store and it doesn’t require any type casting (boxing and unboxing) while storing and retrieving elements so performance will be improved.
Following are the different type of generic collection classes which are provided by System.Collections.Generic namespace.
|List||It is useful to represent a list of objects that can be accessed by index.|
|Queue||It is useful to represent a FIFO (First in, First Out) collection of objects.|
|Stack||It is useful to represent a LIFO (Last in, First Out) collection of objects.|
|SortedList<K,V>||It is useful to represent a collection of key/value pairs that are sorted by a key.|
|Dictionary<K,V>||It is useful to represent a collection of key/value pairs that are organized based on the key.|
|HashSet||It is useful to store a non-duplicate elements.|