Is it insecure normal in .net C #?

I need to create a new String instance from the sbytes array (sbyte []). To do this, I need to convert sbyte [] to sbyte *

Only the unsafe keyword can be used. is this normal or are there other ways to create a string from the sbytes array?

+4
source share
2 answers

First: How to convert sbyte [] to byte [] in C #?

sbyte[] signed = { -2, -1, 0, 1, 2 }; byte[] unsigned = (byte[]) (Array)signed; 

Then:

 string yourstring = UTF8Encoding.UTF8.GetString(unsigned); 
+7
source

Why are you using sbyte?

Encoding.Default.GetString () (and any other encoding) takes a byte[] Array as argument, so you can convert an sbyte[] array using LINQ if all values ​​are non-negative: array.Cast<byte>().ToArray() .

+1
source

All Articles