Why C# change my color structure to ValueType?

做~自己de王妃 提交于 2019-12-12 03:58:02

问题


I have defined following code in C++ CLI.
However when I want to call SetColor the first parameter which is supposed to appear as System.Drawing.Color; appears as ValueType.
This also let me to pass any variable into it. No matter if it's Color or not.

[System::Runtime::CompilerServices::ExtensionAttribute]
public ref class MyExtensions abstract sealed {
public:        
    [System::Runtime::CompilerServices::ExtensionAttribute]
    static System::String^ SetColor(System::String^ in, System::Drawing::Color^ ext) {
        return gcnew System::String("{") +
            ext->R.ToString("X") + ext->G.ToString("X") + ext->B.ToString("X")
            + gcnew System::String("}")  + in;
    }        
};

回答1:


Color is a struct. Remove the ^ from the parameter System::Drawing::Color^ ext.

Also, gcnew System::String("{") is redundant. Just use "{" directly, it's already a String object.



来源:https://stackoverflow.com/questions/15419974/why-c-sharp-change-my-color-structure-to-valuetype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!