I am trying to convert my c structures to c# structures. I am facing one problem as character is one byte representation in c and two bytes in c#.

How to construct xyz structure with character having one byte??

Use a byte array:
Byte[] MyCchars = { (byte)'A', (byte)'B' };This will map to your C array of chars. MyCchars[0] will contain the ASCII code for the character A. But remember, in C# these are still bytes, not characters. Use a cast to char if you want your bytes to be characters.

Use a byte array:
Byte[] MyCchars = { (byte)'A', (byte)'B' };This will map to your C array of chars. MyCchars[0] will contain the ASCII code for the character A. But remember, in C# these are still bytes, not characters. Use a cast to char if you want your bytes to be characters.

No I cant declare byte array. I need to define one character only.
struct xyz{
int i;
char c;
}

Size is 3 bytes if i compile with c.. How where as with c# size becomes 4 bytes as i declare if i declare like
struct xyz {
Int16 i;
Char c;
}
How to make it 3 bytes at the definition only. My structure is fixed size so i cant make any changes to it at runtime

Like this:

struct xyz {
Int16 i;
Byte c;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.