开发者

Convert C Define Macro to C#

How can I convert this C define macro to C#?

#define CMYK(c,m,y,k)       ((COLORREF)((((BYTE)(k)|((WORD)((BYTE)(y))<<8))|(((DWORD)(BYTE)(m))<<16))|(((DWORD)(BYTE)(c))<<24)))

I have been searching for a couple of days and have not been able to figure this out. An开发者_运维百科y help would be appreicated.


C# doesn't support #define macros. Your choices are a conversion function or a COLORREF class with a converting constructor.

public class CMYKConverter
{
    public static int ToCMYK(byte c, byte m, byte y, byte k)
    {
        return k | (y << 8) | (m << 16) | (c << 24);
    }
}

public class COLORREF
{
    int value;
    public COLORREF(byte c, byte m, byte y, byte k)
    {
        this.value = k | (y << 8) | (m << 16) | (c << 24);
    }
}


C# does not support C/C++ like macros. There is no #define equivalent for function like expressions. You'll need to write this as an actual method of an object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜