Search code examples
c#c++-climanaged

How do I do typeof(int) in Managed C++?


I am working on a project now and part of it uses Managed C++. In the managed C++ code, I am creating a DataTable. While defining the Columns for the datatable, I need to specify the Type of the column. In C#, that would:

typeof(int)

but how do I do that in Managed C++?

Thanks!


Solution

  • In C++/CLI, use the typeid keyword.

    e.g.

    Type ^t = Int32::typeid;
    

    In the older "Managed C++ Extensions" syntax, you'd use __typeof(Int32), but that whole version of the language is severely deprecated and you should be using C++/CLI.