欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#中Byte轉(zhuǎn)換相關(guān)的函數(shù)

 更新時間:2016年05月03日 15:11:33   作者:伖先生  
這篇文章主要介紹了C#中Byte轉(zhuǎn)換相關(guān)的函數(shù)介紹,非常具有參考借鑒價值,特此分享到腳本之家平臺供大家學習

 1、將一個對象轉(zhuǎn)換為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、將一個十六進制字符串轉(zhuǎn)換為byte對象,字符串以0x開頭

public static byte GetByteFormHex(string hexValue)
{
try
{
return Convert.ToByte(hexValue, 16);
}
catch 
{
return 0;
}
}

3、將單個字符轉(zhuǎn)換為byte對象

public static byte GetByteFormSingleString(string value)
{
return GetByteFormChar(Convert.ToChar(value));
}

4、將一個字符串轉(zhuǎn)換為byte數(shù)組

public static byte[] GetBytes(string values)
{
return System.Text.Encoding.Default.GetBytes(values);
}

以上內(nèi)容是小編給大家介紹的C#中Byte轉(zhuǎn)換相關(guān)的函數(shù),希望對大家有所幫助!

相關(guān)文章

最新評論