Generic Classes: Lecture No-21 Date-20/04/2011
Generic Classes: Lecture No-21 Date-20/04/2011
Generic Classes: Lecture No-21 Date-20/04/2011
Lecture No-21
Date-20/04/2011
Overview
• Generic classes enables us to create classes and
methods that are independent of contained
types. Instead of writing a number of methods or
classes with the same functionality for different
types, you can create just one method or class.
• For example, the mechanism that supports a
queue is the same whether the queue is storing
items of type int, string, object, or a user-defined
class. So, you might have created several
different versions of the same algorithm to
handle different types of data.
• Through the use of generics, you can define a
solution once, independently of any specific
type of data, and then apply that solution to a
wide variety of data types without any
additional effort.
• Generics are not limited to classes. We can
use generic for the creation of structures,
interfaces, methods, and delegates
What Are Generics?
• The term generics means parameterized types.
• Parameterized types are important because they
enable you to create classes, structures,
interfaces, methods, and delegates in which the
type of data upon which they operate is
specified as a parameter.
• For e.g. using generic we can create a class that
automatically works with different types of data.
A class, structure, interface, method, or delegate
that operates on a parameterized type is called
Generic.
The General Form of a Generic Class