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

Nazeeh picture Nazeeh · Jul 15, 2009 · Viewed 20.7k times · Source

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!

Answer

Daniel Earwicker picture Daniel Earwicker · Jul 15, 2009

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.