值类型为return的cli接口和C#接口实现

值类型为return的cli接口和C#接口实现,c#,interface,c++-cli,value-type,C#,Interface,C++ Cli,Value Type,我有 1.具有声明接口(InterfaceCLI)和实现值类型(PointD)的CLI库 2.C#库的类(PointD)从1实现接口 问题在于C#上奇怪的接口实现。它需要这样的代码 公共价值类型GetPoint() 代替 公共点GetPoint() 示例代码CLI: public value struct PointD //public ref class PointD { public: PointD(double x, double y); // Some stuff };

我有 1.具有声明接口(InterfaceCLI)和实现值类型(PointD)的CLI库 2.C#库的类(PointD)从1实现接口

问题在于C#上奇怪的接口实现。它需要这样的代码 公共价值类型GetPoint() 代替 公共点GetPoint()

示例代码CLI:

public value struct PointD
//public ref class PointD
{
public:
    PointD(double x, double y);
    // Some stuff
};

public interface class InterfaceCLI
{
public:
    double Foo();
    PointD^ GetPoint();
};
示例代码C#:

为什么它要在类Class1中使用ValueType而不是PointD

PointD^ GetPoint();
值类型不是引用类型。所以你不应该在这里用帽子。不幸的是,这种语法在C++/CLI中是允许的,它变成了一个装箱值。非常浪费。在C#中,除了用ValueType模拟它之外,没有直接的等价物


摘下帽子来解决你的问题。

非常感谢。问题解决了。在我看来,我必须对值类型使用PointD%。为什么我不应该在这种情况下使用PointD%?这意味着完全不同的东西,用于通过引用传递函数参数。任何C++/CLI入门书籍都会告诉您这一点。
PointD^ GetPoint();