The problem is that int is not an object .
Object can be marked . The resulting object (aka boxed int) is, of course, an object, but it is no longer int int.
Please note that the β is β I use above is not the same as the C # is operator. My " - " means "converted to implicit link translation ". This meaning is when we speak of covariance and contravariance.
int is implicit, convertible to an object, but it is not a reference conversion. It should be placed in a box.
An House implicitly converted to Asset through a reference conversion. There is no need to create or modify any objects.
Consider the example below. Both House and Asset variables refer to the same object. On the other hand, the integer and boxedInt keep the same value, but they refer to different things.
House house = new House(); Asset asset = house; int integer = 42; object boxedInt = integer;
Boxing and Unboxing is not as simple as it might seem. It has many subtleties and can affect your code in unexpected ways. Mixing boxing with covariance and contravariance is an easy way to make anyone blind.
jpbochi
source share