Skip to content

Latest commit

 

History

History
16 lines (8 loc) · 561 Bytes

DelegateInterface.md

File metadata and controls

16 lines (8 loc) · 561 Bytes

Delegates implementing interfaces

Allow delegates to implement single-method interfaces.

Motivation: Simplifies code and prevents allocations of wrapper classes. It should also be simple to implement as delegates are already compiler-generated classes.

Utilities such as Array.Sort would not need to be implemented twice for both IComparer<T> and Comparison<T> or pay the cost of allocating a wrapper IComparer around a Comparison or vice-versa.

Example:

public delegate int Comparison<in T>(T x, T y) : IComparer<T>.Compare;