Could you help me to understand the error in those case ?
public interface IGeneralInterface
{
}
public class A : IGeneralInterface
{
}
public class B : IGeneralInterface
{
}
public class SomeClass<TGenericType> where TGenericType : IGeneralInterface
{
private TGenericType internalValue;
public SomeClass(TGenericType InitValue)
{
internalValue = InitValue;
}
public TGenericType CreateAnother()
{
TGenericType val1 = new B(); //Error here: class B() could not be converted to TGenericType
return val1;
}
}
Even if I build the SomeClass<T>
as
SomeClass<IGeneralInterface> someClass = new SomeClass<IGeneralInterface>();
I explicity pass base interface to include all (?) cases and it still throw an error