Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys.

i have a CLR project and a c++ managed class.
i need to mimic the behavior of the "is" keyword from c# but i dont know how to do it in managed code.

part of my code:
1.C# code:
C#
public class emailMsg : Msg
{
    string email;
}

2.C++ manged code
C++
Msg^ msg = gcnew Msg();
if (msg is emailMsg)
{
    //DO SOMETHING
}


the above if sentence is not compiling since managed code dont recognize the "is" keyword.
how can i solve it?
Posted

1 solution

C++
dynamic_cast<T^>(expression)


The C# 'is' operator is nothing more than an 'as' cast followed by a check for null, which is exactly the same thing you get by using dynamic_cast in C++ followed by a check for nullptr.
 
Share this answer
 
Comments
Mehdi Gholam 8-Nov-11 4:08am    
5'ed
amir.dar 8-Nov-11 4:51am    
10x. I'll try this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900