C#中一些小技巧
/// <summary>
/// 一个永远不会获得焦点的button
/// </summary>
[Serializable]
public class SpeedButton : Button
{
public CMBSpeedButton()
: base()
{
base.SetStyle(ControlStyles.Selectable, false);
}
}
//字节与16进制数转换
class Util
{
public static byte uniteBytes(byte b1,byte b2)//将两个字节合并成一个16进制数
{
byte retByte=new byte();
string s=Encoding.UTF8.GetString(new byte[]{b1,b2});
retByte = Convert.ToByte("0x"+s, 16);
return retByte;
}
public static string BytesToHexString(byte[] b)
{
//byte[] b = encode.GetBytes(s);//按照指定编码将string编程字节数组
string result = string.Empty;
for (int i = 0; i < b.Length; i++)//逐字节变为16进制字符
{
result +=Convert.ToString(b[i], 16);
}
return result;
}
}