(+N) Consulting Inc.

Consulting | Software Solutions | Training

C# Generics - Interface declaration

I was challenged recently with a question about generics with constraints. The claim was that it's only a compile flaw that allows your to declare an interface for a generic type with a constraint. Namely that the syntax public interface ISomething <T> where T: SomeClass would pass compilation but would not be useful (runtime) because you can't declare a variable ISomething myVar = new ISomething<SomeClass>(); or something to that extent. I went home feeling a bit uneasy about the discussion, then coded this up the way I see it. While it is completely true that you can't 'new' an interface, using an interface that has a generic type... [More]