Tag Archives: .net

Everything related to .NET

UCHAR and SByte

Recently I have to do a lot of C# programming. It’s a quite ok language to be honest. I need to wrap certain unsafe code in C# code. Some of this unsafe code uses the old type UCHAR, which is defined as an unsigned char type with a limit of 0 to 255, inclusive. Perusing some websites to look for some marshaling information I actually find people recommending using the sbyte data type for this. This datatype (sbyte, SByte or the full System.SByte) is a signed 8-bit integer type. This means it has a range of -128 to 127. This is also extensively documented in the sbyte C# reference. So I am left wondering how well these programmers actually do understand their data types.