I tried to convert an Array from byte[]
to sbyte[]
.
Here is my sample Array:
byte[] unsigned = { 0x00, 0xFF, 0x1F, 0x8F, 0x80 };
I already tried this:
sbyte[] signed = (sbyte[])((Array)unsigned);
But it doesn't work. There is no value in the array after this operation.
Does anybody has an better idea?
sbyte[]
in nearly every situation, but is still marked asbyte[]
by the runtime. Not sure what you mean by "there is no value in the array", for me the array is{0, -1, 31, -113, -128}
as expected.sbyte[]
but a dynamic typebyte[]
is valid. The CLR allows this cast, but C# does not. This is a hack, so in most applications you'll want to use @Selman's suggestion.sbyte[]
reference to abyte[]
.