Casting does not create a new object (at least, not unless new conversion operators have been defined, which is uncommon in non-numeric types, and doesn't apply in your example). It merely instructs the compiler how to "treat" an object. In the case you present, you're telling the compiler "don't worry, trust me, B
is actually a Bitmap
". If it turns out you've told it a fib, the runtime will catch you on it by throwing an InvalidCastException
at runtime.
MSDN has some more information.
A cast is a way of explicitly informing the compiler that you intend to make the conversion and that you are aware that data loss might occur
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…