I have been programming for a while now but am relatively new to c#. Long story short, I need to do the following:
public abstract class SomeBaseClass
{
}
public class SomeSmallClass<T> where T : SomeBaseClass
{
}
private List<SomeSmallClass<SomeBaseClass>> listOfData = new List<SomeSmallClass<SomeBaseClass>>();
public void AddToList<T>() where T : SomeBaseClass
{
listOfData.Add(new SomeSmallClass<T>());
}
This gives a nasty red underline and a compiling error that reads "Cannot Implicitly convert SomeSmallClass to SomeSmallClass".
What I don't understand is why the compiler doesn't know that T will always be a SomeBaseClass. Does anyone know what's happening here?
Note: there is no problem with instancing the SomeSmallClass only with adding it to the list.
Any help is much appreciated.