C# Subclassing Generic Types

In this chapter you will learn:

  1. What
  2. Example for Subclassing Generic Types

Description

A generic class can be subclassed just like a nongeneric class.

Example

The subclass can leave the base class's type parameters open, as in the following example:


class Stack<T>                   {...}
class SpecialStack<T> : Stack<T> {...}

Or the subclass can close the generic type parameters with a concrete type:


class IntStack : Stack<int>  {...}

A subtype can also introduce fresh type arguments:


class List<T>                     {...}
class KeyedList<T,TKey> : List<T> {...}

Next chapter...

What you will learn in the next chapter:

  1. What is C# Generic Delegate
  2. Syntax to create Generic Delegate
  3. Example for Generic Delegate
Home »
  C# Tutorial »
    C# Types »
      C# Generics
C# Generic Types
C# Generic Methods
C# default Generic Value
C# Generic Constraints
C# Subclassing Generic Types
C# Generic Delegate
C# Type Parameters