So I don't have an in-depth knowledge of how data is stored in the .NET Framework in terms of custom types, but I was looking for an explanation on how the casting system is working.
For example, if one were to do an explicit cast from a ValueType Struct like Char into Byte as follows:
char C = '#';
byte B = (byte)C;
Console.WriteLine(B.GetType()); // Outputs "Byte"
I would be told that B is a Byte, which makes perfect sense.
Now say I cast from a Custom Class Flower to its base Class Plant, why does the output reveal the derived class regardless of the cast as follows:
class Plant{}
class Flower:Plant{}
.
Flower Rose = new Flower();
Plant RoseBush = (Plant)Rose;
Console.WriteLine(RoseBush.GetType()); //Outputs Flower
Plant Rose = new Flower();
Plant RoseBush = (Plant)Rose;
Console.WriteLine(RoseBush.GetType()); //Outputs Flower as well
I guess my question is, why doesn't the type expose the current type of the custom type, that being Plant, and why does this differ from the Value Types at the beginning?
Also, why is the two examples with the flower and plants, although written differently on the first line, output the same thing?