   [.net] C++/CLI is and as equivalents
  I know that C# has some 'is' and 'as' operators, what is the equivalent if I want to do the same in C++/CLI?Trying to use is and as doesn't work and as they are not highlighted I expect they are not part of C++/CLI syntax. I realise safe_cast is available but this can only be used in conjuction with catching errors.examples of what I want to do:if(this_var is System::Int32){   ...}System::Int32 qq = this_var as System::Int32;Any help appreciated.- stevenmarky   
  "as" in C# basically boils down to wrapping an explicit type cast in a try/catch block to ensure it uses null instead of erroring if the typecast isn't valid:IncidentClass a = new IncidentClass();ResultantClass b;try{    b = (ResultantClass)a;}catch{    b = null;}C++/CLI doesn't exactly have a construct for this. You would use safe_cast to do the type cast, but there isn't anything to automatically guard the conversion like that.However, you can write something similar with a templated function:template<class ToType, class FromType> ToType as(FromType u){ToType t;try{t = (ToType)u;}catch(System::Exception^){t = nullptr;}return t;}public ref class A{public:int x;A(){x=5;}};public ref class B{public:int y;B(){y = 7;}};int Main(){A^ a = gcnew A;B^ b = as<B^>(a);if(b == nullptr){Console::WriteLine("Failed");}else{Console::WriteLine("Success");}}as for "is", I'm not sure that this is a way to exactly duplicate it, but this might come close. I'm not entirely certain on the exact semantics of "is" right now, but if this isn't right, then all you should have do to is change "IsAssignableFrom" to "Equals".template<class BaseType, class DerivedType>bool is(DerivedType d){return BaseType::typeid->IsAssignableFrom(DerivedType::typeid);}public ref class A{public:int x;A(){x=5;}};public ref class B{public:int y;B(){y = 7;}};public ref class C : public B{};int Main(){A^ a = gcnew A;B^ b = gcnew B;C^ c = gcnew C;Console::WriteLine(is<A^>(b));Console::WriteLine(is<B^>(b));Console::WriteLine(is<B^>(c));}