为什么C#将我的颜色结构更改为ValueType? [英] Why C# change my color structure to ValueType?

查看:153
本文介绍了为什么C#将我的颜色结构更改为ValueType?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++ CLI中定义了以下代码。

然而,当我想调用SetColor时,第一个参数应该显示为System.Drawing.Color;显示为ValueType。

这也让我将任何变量传递给它。无论是 Color 还是不是。

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;
    }        
};


推荐答案

Color是一个结构体。从参数 System :: Drawing :: Color ^ ext 中删除​​ ^

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

此外, gcnew System :: String({)是多余的。直接使用{,它已经是一个String对象。

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

这篇关于为什么C#将我的颜色结构更改为ValueType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆