O'Reilly logo

C#: A Beginner's Tutorial by Jayden Ky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12

Generics

Generics were one of the most prominent features added to .NET Framework 2.0. With generics you can write a parameterized type and create instances of it by passing a type or types. The objects will then be restricted to the type(s). In addition to parameterized types, generics support parameterized methods.

The benefit of generics include stricter type checking at compile time and performance improvement. In addition, generics eliminate most type castings you would otherwise have to perform when working with members of the System.Collections namespace.

This chapter explains how you can use and write generic types. It starts with the section “Why Generics?”  and then presents some examples of generic types. After a discussion ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required