On MSDN - C# Programming guide Constraints on Type Parameters, it says:
where T : interface_name
The type argument must be or implement the specified interface. Multiple interface constraints can be specified. The constraining interface can also be generic.
Could somebody kindly explain, what it means to have a generic interface? And explain how that can be a constraint and what it provides?
A simple
example and a simple
explanation is highly appreciated.
Many thanks in advance : )
You can use a generic interface as a constraint. For example:
class MyClass<T> where T:IEnumerable<string>
you can even substitute the generic parameter of the type you define into your constraint:
class MyClass<T> where T:IEnumerable<T>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With