#include "stdafx.h"
using namespace System;
ref class A {};
ref class B : public A {};
ref class C {};
void main()
{
Object ^v1 = gcnew A();
Object ^v2 = gcnew B();
Object ^v3 = gcnew C();
A ^a1 = gcnew A();
A ^a2 = gcnew B();
A ^a3 = dynamic_cast(v1); // downcast
A ^a4 = dynamic_cast(v2); // downcast
B ^b1 = gcnew B();
B ^b2 = dynamic_cast(v2); // downcast
B ^b4 = dynamic_cast(a2); // downcast
C ^c1 = gcnew C();
C ^c2 = dynamic_cast(v1); // Fails c2 = null. Miss match classes
C ^c3 = static_cast(v2); // c3 has invalid value of type B class
C ^c4 = safe_cast(v3); // downcast
C ^c5 = (C^)(v3); // downcast
}