c# - What changes does an object undergo during a cast in .net? -
i know happens object when cast. layout of object gets restructured or method table changes or ensure assignments don't break during runtime ?
none!
all doing "pretending" different type. of course, if doesn't inherit type (or instance of type when downcasting) cast fails , nothing (null) when using "as" operator cast, , explicit (c-style) cast throw.
unless, is, dealing value types (especially number types). if following:
double mydouble = 1.5f; int myint = (int)mydouble; double myotherdouble = (double)myint; you 1 myint , myotherdouble, because number truncated when performing conversion. of other value types don't support kind of casting, because conversion not defined.
Comments
Post a Comment