O'Reilly logo

A Programmer's Guide to C# 5.0, 4th Edition by Nick Wienholt, Eric Gunnerson

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 17

image

Generic Types

It is sometimes useful to separate the implementation of a class—the members and methods that it exposes—from the type it is using. A list of items, for example, behaves in the same way whether it is a list of Decimal items or a list of Employee items.

A generic type is used to create such an implementation. The word generic refers to the implementation being written using a generic type rather than a specific one.

A List of Integers

Consider the following class that stores integer values:

public class IntList{    int m_count = 0;    int[] m_values;    public IntList(int capacity)    {       m_values = new int[capacity]; ...

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