C产品在市场上有哪些独特优势?
- 内容介绍
- 文章标签
- 相关推荐
本文共计254个文字,预计阅读时间需要2分钟。
1. 将对象转换为byte对象csharppublic 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. 将十六进制字符串转换为bytecsharppublic static byte HexStringToByte(string hex){ byte retInt=0; if (hex !=null) { if (byte.TryParse(hex, System.Globalization.NumberStyles.HexNumber, null, out retInt)) { return retInt; } } return 0;}
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转换相关的函数,希望对大家有所帮助!
本文共计254个文字,预计阅读时间需要2分钟。
1. 将对象转换为byte对象csharppublic 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. 将十六进制字符串转换为bytecsharppublic static byte HexStringToByte(string hex){ byte retInt=0; if (hex !=null) { if (byte.TryParse(hex, System.Globalization.NumberStyles.HexNumber, null, out retInt)) { return retInt; } } return 0;}
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转换相关的函数,希望对大家有所帮助!

