I have generic class with constraint where T : IEnumerable<object>
. I expected that I can use any type instead object
.
But when I try to create an instance of my generic class with List<SomeValueType>
Visual studio gives me an error like There is no implicit reference conversion from System.Collections.Generic.List<ConsoleApp.Program.ValueType>' to System.Collections.Generic.IEnumerable<object>'
. So my question is: why I can't use both value and reference types in this case even though they're both inherited from object
?
static void Main(string[] args)
{
var example1 = new GenericClass<List<ReferenceType>>(); // it's ok
// There is no implicit reference conversion
// from 'System.Collections.Generic.List<ConsoleApp.Program.ValueType>'
// to 'System.Collections.Generic.IEnumerable<object>'
var example2 = new GenericClass<List<ValueType>>();
}
public class GenericClass<T> where T : IEnumerable<object>
{
}
public class ReferenceType
{
}
public struct ValueType
{
}