I am new to C# programming (or programming in general) and having a problem of setting raw textbox string value into byte value within a byte array.
My question is how can I convert the string HEX value from a text box string input into an exact byte value within a byte array as shown in the example code below.
I get the following error from my example code below;
"System.FormatException: 'The input string '0x50' was not in a correct format.'"
I have read up on byte, char, and string data types but still cannot really understand how to slot in the HEX string value into the byte value.
Thanks for any help.
string byte3 = "0x50";//value from textBox at runtime
string byte4 = "0xEF";//value from textBox at runtime
byte[] bytes = new byte[5];
bytes[0] = 0xAB; //hard coded value
bytes[1] = 0x0F; //hard coded value
bytes[2] = 0x02; //hard coded value
bytes[3] = Convert.ToByte(byte3); // from textbox string to byte value
bytes[4] = Convert.ToByte(byte4); // from textbox string to byte value
void ThenIUseTheBytesArrayInAnotherMethod(bytes){
}
I have read up on byte, char, and string data types but still cannot really understand how to slot in the HEX string value into the byte value.