Generic function where generic type is any interface?

You can constrain the type to a specific interface, but not "any" arbitrary interface This is allowable public T MyFunction() where T : IMyInterface { return null; } This will let you pass any object which implements that specific interface Edit: Given your goals, from the comments, I would personally probably just put in some runtime checking: public IEnumerable LoadInterfaceImplementations() { Type type = typeof(T); if (!type. IsInterface) throw new ArgumentException("The type must be an Interface"); // ... }.

You can constrain the type to a specific interface, but not "any" arbitrary interface. // This is allowable public T MyFunction() where T : IMyInterface { return null; } This will let you pass any object which implements that specific interface. Edit: Given your goals, from the comments, I would personally probably just put in some runtime checking: public IEnumerable LoadInterfaceImplementations() { Type type = typeof(T); if (!type.

IsInterface) throw new ArgumentException("The type must be an Interface"); // ... }.

Excellent. Thank you. – gbogumil Jun 18 '10 at 17:39.

No, there's no way to constrain the type to interfaces only.

You have to use a specific interface. You could create a base interface that all your other interfaces derive from and use that as the constraint.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions