当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Set the value of a new byte using a string?

问题描述:

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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: