/// <summary>
/// 将对象转换成字节数组
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private byte[] objToBytes(object obj)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, obj);
byte[] arrBytes = ms.GetBuffer();
ms.Close();
return arrBytes;
}
/// <summary>
/// 将字节数组转成字符
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
private string bytesToString(byte[] bytes)
{
BinaryFormatter bfFormatter = new BinaryFormatter();
string str = bfFormatter.Deserialize(new MemoryStream(bytes)) as string;
return str;
}