1、将一个对象转换为byte对象
public static byte getbyte(object o) { byte retint = 0; if (o != null) { byte tmp; if (byte.tryparse(o.tostring().trim(), out tmp)) { retint = tmp; } } return retint; }
2、将一个十六进制字符串转换为byte对象,字符串以0x开头
public static byte getbyteformhex(string hexvalue) { try { return convert.tobyte(hexvalue, 16); } catch { return 0; } }
3、将单个字符转换为byte对象
public static byte getbyteformsinglestring(string value) { return getbyteformchar(convert.tochar(value)); }
4、将一个字符串转换为byte数组
public static byte[] getbytes(string values) { return system.text.encoding.default.getbytes(values); }
以上内容是小编给大家介绍的c#中byte转换相关的函数,希望对大家有所帮助!
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论