LANGUAGE

Generic where constraint

Restricts generic type arguments to types implementing the comparison interface.

Formal Syntax & Structure

csharp syntaxcsharp
where T : IComparable<T>

Working Example

Example Snippetcsharp
System.Console.WriteLine(Compare(2, 3) < 0);static int Compare<T>(T a,T b) where T : System.IComparable<T> => a.CompareTo(b);
C# & .NET Reference