Why does it work?

Why fire the cast to interface type, after packaging significant of type int?402d8bd4624944fdb518fe69ab1d4148.PNG
July 9th 19 at 14:03
3 answers
July 9th 19 at 14:05
Solution
Also Packed Int32 implement the IComparable interface, but Packed as Int32 was given to the Object type required the explicit castes to the interface type.
July 9th 19 at 14:07
But what about the packaging? - nikita.Stracke commented on July 9th 19 at 14:10
Eating... Well, it will happen, why it should break this mechanism? - buford_Hand41 commented on July 9th 19 at 14:13
Creates an object on the heap, the value of the int field is copied to this new object, and the object is cast to type object that does not implement the IComparable interface - nikita.Stracke commented on July 9th 19 at 14:16
Yes, but int does not cease to be an int-if that referenced object type.

In this case obj is reference type object that points to the Packed int. When you privtate it(the link) to IComparable, then Rantum looks at the place where it points to, and there is an int that knows what is IComparable.

I recommend reading about inheritance and addressing in memory. - buford_Hand41 commented on July 9th 19 at 14:19
9b41df0723ab47f19f79a2d1575baab3.png - buford_Hand41 commented on July 9th 19 at 14:22
o_O - buford_Hand41 commented on July 9th 19 at 14:25
I do not understand why with implicit custom gives a compilation error, but with obvious everything is OK - nikita.Stracke commented on July 9th 19 at 14:28
e295cec982be499c8023fb79cea48e64.PNG - nikita.Stracke commented on July 9th 19 at 14:31
This allows to reduce the number of silly logic errors in the transformations, all otvestvennost for "strange" transformation lies on the shoulders of the programmer. - buford_Hand41 commented on July 9th 19 at 14:34
: "Explicit is better than implicit" - audra_Ruecker commented on July 9th 19 at 14:37
July 9th 19 at 14:09
When you write "number." in the last line the system has no idea what obj contains INTOSAI value and just shows the methods for the interface IComparable.
But this does not mean that the code will work )

Find more questions by tags C#