.NET 4 supports joint and contravariance. However, only reference types are supported, not value types. Why is this?
Basically, the CLR should know that it can treat the value of the source type as the value of the target type without performing any additional conversions - just like that, the bit pattern for the source value must be valid as the target value. Views must be the same. Otherwise, the CLR will need additional information to properly convert at the right time.
- . ( :).
; . ,
Func<int> f1 = ()=>2; Func<object> f2 = f1; object o1 = f1(); object o2 = f2();
, . ; :
object o1 = BoxIntegerToObject(f1());
, , o2, int. ? f2, . f2, f2 f1, f1 , unboxed int.
, , , , , , . Func<int> Func<object>.
Func<int>
Func<object>
Both forms of variance are defined in terms of inheritance: value types are not inherited.
Source: https://habr.com/ru/post/1610193/More articles:JPanel background image does not apply to JPanel inside it - javaC # Combo Box only kits in debug mode - debuggingThe generic type restriction cannot be used in IEnumerable? - c #How to create an https server using synapse in lazarus - lazarusBeautifulSoup replaceWith () method adds escaped html, doesn't require it - pythonThe semicolon is calculated using the underscore in int - javaPython working function not working - pythonWhy does include behave differently at the top level? - ruby | fooobar.comHow to create a rounded UIButton with a radius of only the left and bottom left corner - iosHow to tell classes from interfaces in Roslyn `BaseList`? - syntaxAll Articles