I want to achieve something like this in C# 3.5:
public void Register<T>() : where T : interface {}
I can do it with class or struct, but how to do it with an interface?
If you are asking about adding a constraint to a specific interface, that's straightforward:
public void Register<T>( T data ) where T : ISomeInterface
If you are asking whether a keyword exists like class or struct to constrain the range of possible types for T, that is not available.
While you can write:
public void Register<T>( T data ) where T : class // (or struct)
you cannot write:
public void Register<T>( T data ) where T : interface
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