Subscribe

RSS Feed (xml)

Generics Means?

At its core, the term generics means parameterized types. Parameterized types are important because they enable you to create classes, interfaces, methods, and delegates in which the type of data operated on is specified as a parameter. Using generics, it is possible to create a single class, for example, that automatically works with different types of data. A class, interface, method, or delegate that operates on a parameterized type is called generic, as in generic class or generic method.

It is important to understand that C# has always given you the ability to create generalized classes, interfaces, methods, and delegates by operating through references of type object. Because object is the base class of all other classes, an object reference can refer to any type object. Thus, in pre-generics code, generalized code used object references to operate on a variety of different types of objects. The problem was that it could not do so with type safety.

Generics add the type safety that was lacking. They also streamline the process because it is no longer necessary to employ casts to translate between object and the type of data that is actually being operated upon. Thus, generics expand your ability to reuse code and let you do so safely and easily.

No comments:

Post a Comment

Archives

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail