마지막 줄이 허용되지 않는 이유는 무엇입니까?IEnumerable <struct>을 IEnumerable <object>으로 캐스팅 할 수없는 이유는 무엇입니까?
double은 객체에서 파생되지 않는 값 유형이므로 공분산이 작동하지 않습니까?
가이 일 할 수있는 방법이 없다는 것을 뜻 :public interface IMyInterface<out T>
{
string Method();
}
public class MyClass<U> : IMyInterface<U>
{
public string Method()
{
return "test";
}
}
public class Test
{
public static object test2()
{
IMyInterface<double> a = new MyClass<double>();
IMyInterface<object> b = a; // Invalid cast!
return b.Method();
}
}
을 내가 쓸 필요가 나의 IMyInterface<T>.Cast<U>()
을 자신의 것을 할까?
[공분산과 반항성이 값 유형을 지원하지 않는 이유]의 복제본 (http://stackoverflow.com/questions/12454794/why-covariance-and-contravariance-do-not-support-value-type) – nawfal