问题描述:

I have a string with a numerical value that will fit into a data type byte variable (e.g. "243").

I want to set the byte to the numerical value of the string, something similar to byte myByte = 243; but using the string instead. How would this be possible?

网友答案:

You can use this to convert your string value to byte:

byte MyByte = Convert.ToByte("243");
网友答案:

Use byte.Parse() method:

byte myByte = byte.Parse("243");
网友答案:

You can do something like this

string myString = "243";
var byteData = Convert.ToByte(myString);
相关阅读:
Top