Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using generic interface in a generic class

How force to use class that implement generic interface in class?
Is something like this possible?

public interface IGeneric<T>
{
    T Value {get;}
}

//public class MyList<IGeneric<T>> {}//not allowed

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Something like this:

public class MyList<T> where T : IGeneric<T>
{
    
}

Or this:

public class MyList<T> : IGeneric<T>
{
    public T Value => throw new NotImplementedException();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading