posted 20 years ago
Ok, I'm on a posting binge.
I just wanted to get this clear, because after missing this one question on the John Hunt exam, it is turning my world upside down.
Ok implicit casting. If I want to do an implicit casting, the object that I am trying to implicitly cast, must be of the same or smaller type than the object that is to contain it. Meaning
int i = s // a short
int i = c // a char, not even sure if that is possible
short s = b // a byte
but I can use explicit casting to do almost anything I please...meaning the explicit cast will be chopping off information just to make it fit. Like if I tried to do
byte b = (byte)s // as short
the (byte) casting will just chop all the information off the s.
If that is the case, does the explict casting do the same type of "chopping" to objects? Like if I did a Car myCar = (Car)H*nda explicit casting, will myCar just be a Car again, or will "H*nda Information" still linger somewhere, so that if I did a (H*nda)myCar, all the "Honda Information" will come back