Home Substituting implementations into the T of a parameterized class of type T
Reply: 0

Substituting implementations into the T of a parameterized class of type T

user633
1#
user633 Published in May 25, 2018, 6:52 pm

Say I have a setup like

public interface IMyInterface { }

public class MyImplementation : IMyInterface { }

public class MyClass<T> where T : IMyInterface { }

I figured out that I can't do a substitution like

var list = new List<MyClass<IMyInterface>>()
{
   new MyClass<MyImplementation>()
}

as I'll get the error

Cannot convert from MyClass<MyImplementation> to MyClass<IMyInterface>

Does that mean what I'm trying to do is code smell?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316321 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO