I am trying to run the following code :
classA = classD;
to assign the values in classA to classD (the variable is being shared from another class called ‘classC’).
the above line would normally work in C++ but in C# its returning an error! is this possible in C#?
From the comments
A : D, so allAareD, but not allDare necessarilyA.So with two variables:
We need
This does a type-check, to confirm that the specific
classDis actually also anA. If this is the case (or it isnull) then the assignment is successful; otherwise an exception occurs.This is to prevent you assigning something to
classAthat is actually not really anA.Note it is implicit the other way, since the compiler knows it to be valid: