C ++的VARIANT数据类型到C# [英] VARIANT datatype of c++ into c#
问题描述
什么是C#相当于C ++的VARIANT数据类型?
What is equivalent of VARIANT datatype of C++ in C#?
我在C ++代码,它使用VARIANT数据类型,我怎么可以转换的代码在C#?
I have code in C++ which uses VARIANT datatype, how can i convert that code in C# ?
推荐答案
这是一个棘手的问题。
This is a tricky question.
从C#4,你可以使用的动态的指示,该类型是在运行时称。
From c# 4, you can use dynamic to indicate that the type is known at run-time.
这是我个人的理解,不过,C ++需要在编译时已知的类型。因此,你可能会考虑在C#中使用对象
,但对象
是存在的类型。
By my personal understanding, however, c++ requires the type known at compile time. Thus you might consider to use object
, but object
in c# is existent type.
对于多类型,单值变种(AKA多态性)的概念,你不会需要找到在C#中相应类型,只是定义的类和接口,可以随时引用对象,因为它的接口,它的类实现。
For the concept of multi-type, single value(AKA polymorphism) of VARIANT, you would not need to find a corresponding type in c#, just define your classes and interfaces, you can always reference an object as it's interface which the class implements.
如果您要移植的代码,找出语法,你可以在LHS和类型的考虑只是使用在编译时是已知的,然后使用 VAR 。
If you are porting the code, and to figure out a syntax that you can simply use in LHS and for the considering of the type is known at compile time, then use var.
这篇关于C ++的VARIANT数据类型到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!