Casting a parent class to a child class



Hi guys,

Sorry for this stupid question, but I don't know why it isn't working.

Here is my (example) code:

namespace Test {
class A {
public string Label1;
}

class B : A {
public string Label2;
}

class Program {
static void Main(string[] args) {
A test = new A();
B test2 = (B)test;
}
}
}

It work fine with the compiler, but when executing, it ends with an
InvalidCastException error. Why?

Thank you.


.