Given the following c++/cli code:
public ref class A
{
public:
typedef System::String B;
};
How can I get the following C# code to work:
var b = new A.B();
EDIT: if it helps, the typedef
is not a hard requirement. My goal was to end up with a type defined once and usable in both worlds.
C# doesn't have typedefs. It does have a form of type aliases made with using declarations, but those don't support your usage (the type alias has to be repeated in every file where it is used, it isn't carried with the containing type).
It's very rare for a language to support consuming a feature from another language, that the first doesn't itself support. And, no surprise, C# doesn't support typedefs declared in C++/CLI any more than it supports typedefs declared in C#.
If you have code that needs this feature, write it in C++/CLI, and call it from C#.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments