About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Getting Started with Generics

Generics allow developers to define types and methods that are parameterized with type parameters. Those parameters are ultimately filled in when such types or methods are used. Let’s concentrate on generic types for the time being, deferring treatment of methods until later.

When creating a generic type, whether it’s a class, struct, interface, or delegate, you’re adding one or more type parameters to the type declaration. On the other side of the picture, a user of the type can specify types for those parameters. Let’s take a look at an example to set the scene:

class List<T> {    private T[] _elements;    ...    public T this[int i] {        get { return _elements[i]; }        set ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required