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
Something like this:
void Main()
{
MyList<string> myList = new MyList<string>(new Generic());
}
public interface IGeneric<T>
{
T Value { get; }
}
public class MyList<T>
{
private IGeneric<T> _generic;
public MyList(IGeneric<T> generic)
{
_generic = generic;
}
}
public class Generic : IGeneric<string>
{
public string Value => throw new NotImplementedException();
}
Or like this:
void Main()
{
MyList<Generic, string> myList = new MyList<Generic, string>();
//Or MyList<IGeneric<string>, string> myList = new MyList<IGeneric<string>, string>();
}
public interface IGeneric<T>
{
T Value { get; }
}
public class MyList<G, T> where G : IGeneric<T>
{
}
public class Generic : IGeneric<string>
{
public string Value => throw new NotImplementedException();
}
code MyList<IGeneric<string>> myList = new MyList<IGeneric<string>>(); myList needs to have type MyList<string>, but if you can edit your current interface + class + myList declaration into the question we can answer more specifically.MyList<string> don't work. I don't understand "edit your ... declaration to the question". Example
class MyList<T> : IGeneric<T>