C# 转换为c++;字节数组到c的结构#
我似乎不知道该怎么做。我在C# 转换为c++;字节数组到c的结构#,c#,c++,struct,C#,C++,Struct,我似乎不知道该怎么做。我在c++中有一小部分代码,我需要在c#中有同样的代码。以下是c++代码: struct Texel { unsigned char r, g, b, a; }; Texel mytexturedata[] = { {0x00, 0xFF, 0x00, 0xFF}, // green {0xFF, 0xFF, 0x00, 0xFF}, // yellow {0xFF, 0x00, 0x00, 0xFF}, // red }; 你是如何做到这一点的 谢
c++
中有一小部分代码,我需要在c#
中有同样的代码。以下是c++
代码:
struct Texel { unsigned char r, g, b, a; };
Texel mytexturedata[] =
{
{0x00, 0xFF, 0x00, 0xFF}, // green
{0xFF, 0xFF, 0x00, 0xFF}, // yellow
{0xFF, 0x00, 0x00, 0xFF}, // red
};
你是如何做到这一点的
谢谢 将结构转换为类
public class Texel
{
public byte r { get; set; }
public byte g { get; set; }
public byte b { get; set; }
public byte a { get; set; }
}
然后你可以这样做你的作业
Texel[] mytexturedata =
{
new Texel() { r = 0x00, g = 0xFF, b = 0x00, a = 0xFF }, // Green
new Texel() { r = 0xFF, g = 0xFF, b = 0x00, a = 0xFF }, // Yellow
new Texel() { r = 0xFF, g = 0x00, b = 0x00, a = 0xFF } // Red
};
将结构转换为类
public class Texel
{
public byte r { get; set; }
public byte g { get; set; }
public byte b { get; set; }
public byte a { get; set; }
}
然后你可以这样做你的作业
Texel[] mytexturedata =
{
new Texel() { r = 0x00, g = 0xFF, b = 0x00, a = 0xFF }, // Green
new Texel() { r = 0xFF, g = 0xFF, b = 0x00, a = 0xFF }, // Yellow
new Texel() { r = 0xFF, g = 0x00, b = 0x00, a = 0xFF } // Red
};
Texel[]mytexturedata={new Texel(){r=0x00,g=0xFF,b=0x00,a=0xFF},…}代码>更改为类Texel{byte r{get;set;}byte g{get;set;}byte b{get;set;}byte a{get;set;}
。顺便说一句,unsigned char
对应于C#中的byte
,char
是16位宽(UTF-16)。我认为byte比C#中的unsigned char类型更好Texel[]mytexturedata={new Texel(){r=0x00,g=0xFF,b=0x00,a=0xFF},…}代码>更改为类Texel{byte r{get;set;}byte g{get;set;}byte b{get;set;}byte a{get;set;}
。顺便说一句,unsigned char
对应于C#中的byte
,char
是16位宽(UTF-16)。我认为byte比C#中的unsigned char类型更好。