C# – How to Convert String to Byte Array

arraysc++

I am getting an error reading:

Cannot implicitly convert type 'String' to 'Byte[]'

I think 'byte[]' is byte array – if it isn't please correct me.

I have tried another solution on this website but I did not understand. I'm making a c# 'RTM tool' and this is what put in :

byte[] bytes = (metroTextBox2.Text);   
Array.Resize<byte>(ref bytes, bytes.Length + 1);   
PS3.SetMemory(0x2708238, bytes);

Best Answer

You can try like this:

string str= "some string";
var bytes = System.Text.Encoding.UTF8.GetBytes(str);

And to decode:

var decodeString = System.Text.Encoding.UTF8.GetString(bytes);
Related Question