| o Reference types § ref class RefClass; § ref struct RefClass; |
| § value class ValClass; § value struct ValClass; o Interfaces § interface class IType; § interface struct IType; o Enumerations § enum class Color; § enum struct Color; |
| o class Native; o struct Native; |
| using namespace System; interface class IDog { void Bark(); }; ref class Dog : IDog { public: void Bark() { Console::WriteLine("Bow wow wow"); } }; void _tmain() { Dog^ d = gcnew Dog(); d->Bark(); } |
| void _tmain() { int z = 44; Object^ o = z; //implicit boxing int y = *reinterpret_cast<int^>(o); //unboxing Console::WriteLine(" ",o,z,y); z = 66; Console::WriteLine(" ",o,z,y); } |
| void _tmain() { int z = 44; float f = 33.567; Object^ o1 = z; Object^ o2 = f; Console::WriteLine(o1->GetType()); Console::WriteLine(o2->GetType()); } // Output // System.Int32 // System.Single |
| void _tmain() { int z = 44; float f = 33.567; Object^ o1 = z; Object^ o2 = f; int y = *reinterpret_cast<int^>(o2);//System.InvalidCastException float g = *reinterpret_cast<float^>(o1);//System.InvalidCastException } |
| void Box2() { float y=45; Object^ o1 = y; } |
| .maxstack 1 .locals (float32 V_0, object V_1) ldnull stloc.1 ldc.r4 45. stloc.0 ldloc.0 box [mscorlib]System.Single stloc.1 ret |
用户评论