Generic Constraints thougths

There are 3 types of constraints.


A derivation constraint indicates to the compiler that the generic type parameter derives from a base type such an interface or a particular base class.

class LinkedList where K : IComparable

A default constructor constraint indicates to the compiler that the generic type parameter exposes a default public constructor (a public constructor with no parameters).

class Node where T : new()

A reference/value type constraint constrains the generic type parameter to be a reference or a value type.

class MyClass where T : struct class MyClass where T : class


 

Latest Posts

Popular Posts