#1,135 – Overloading a Generic Class

generic class is a class that takes one or more type parameters, which it then uses in the definition of the class.  It can be thought of as a template for a class.

    public class Pile<T>

A generic class can have more than one type parameter.

    public class DoublePile<T1, T2>

You can also declare two different generic classes having the same name, differing only in the number of their type parameters.  The two classes will be treated as two completely different classes.

    public class Pile<T>

    public class Pile<T1, T2>

The appropriate class will be used based on the number of arguments provided when the type is constructed.

            Pile<int> someInts = new Pile<int>();
            Pile<string, double> namedDoubles = new Pile<string, double>();

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #1,135 – Overloading a Generic Class

  1. Pingback: Dew Drop – July 10, 2014 (#1811) | Morning Dew

  2. Pingback: #1,136 – Overloading a Generic Method | 2,000 Things You Should Know About C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: