EDIT: updated the question after PostMan pointed out the error on my part
Just out of curiosity, does anybody know why type inference is not supported for constructor the way they are for generic methods? i.e.
public class MyType<T>
{
private readonly T field;
public MyType(T value) { field = value; }
}
var obj = new MyType(42); // why can't type inference work out that I want a MyType<int>?
though you could get around this with a factory class
public class MyTypeFactory
{
public static MyType<T> Create<T>(T value)
{
return new MyType<T>(value);
}
}
var myObj = MyTypeFactory.Create(42);
Is there a practical or philosophical reason why the constructor can't support type inference?