What is C#.NET Generics & usage of Generics ?

Generics allow you to define type-safe data structures, without committing to actual data types. It allows writing less but more effective code. Generic provides flexibility and power but the developer needs to be responsible while using it.

Generic types to maximize code reuse, type safety, and performance.

They can be used to create collection classes.

Generic collection classes in the System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace.

The classes and the methods can treat the values of different types uniformly with the use if generics.

The usage of generics is advantageous as:

    They facilitate type safety

    They facilitate improved performance

    They facilitate reduced code

    They promote the usage of parameterized types

The CLR compiles and stores information related to the generic types when they are instantiated. (The generic type instance refers to the location in memory of the reference type to which it is bound for all the instances of the generic type.)
Tags:
Hot on Web:


About author