C# 如何在托管 C++ 中执行 typeof(int)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1133221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:00:37  来源:igfitidea点击:

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

c#c++-climanaged

提问by Nazeeh

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:

我现在正在开发一个项目,其中一部分使用 Managed C++。在托管 C++ 代码中,我正在创建一个 DataTable。在为数据表定义列时,我需要指定列的类型。在 C# 中,这将:

typeof(int)

类型(整数)

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

但是我如何在托管 C++ 中做到这一点?

Thanks!

谢谢!

采纳答案by Daniel Earwicker

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

在 C++/CLI 中,使用 typeid 关键字。

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.

在较旧的“托管 C++ 扩展”语法中,您会使用__typeof(Int32),但该语言的整个版本已被严重弃用,您应该使用 C++/CLI。