C# 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> {...}




















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor