BitConverter提供了很多方法:
转换到字节数组的:
public static byte[] GetBytes(bool);
public static byte[] GetBytes(char);
public static byte[] GetBytes(double);
public static byte[] GetBytes(short);
public static byte[] GetBytes(int);
public static byte[] GetBytes(long);
public static byte[] GetBytes(float);
public static byte[] GetBytes(ushort);
public static byte[] GetBytes(uint);
public static byte[] GetBytes(ulong);
转换到字节数组的:
public static byte[] GetBytes(bool);
public static byte[] GetBytes(char);
public static byte[] GetBytes(double);
public static byte[] GetBytes(short);
public static byte[] GetBytes(int);
public static byte[] GetBytes(long);
public static byte[] GetBytes(float);
public static byte[] GetBytes(ushort);
public static byte[] GetBytes(uint);
public static byte[] GetBytes(ulong);
解决方案 »
- 求救,installshield2008 修改了默认安装目录 死了
- datagrid换行显示文本数据问题
- treeview复选框,多选时的显示问题。c#
- 关于水晶报表最基本的问题:请问水晶报表绑定数据与不绑定数据的区别。
- 怎么用C#把用户从一个ou移动到另外一个ou?
- Winform APP处理一系列数据时为何窗体像死掉一样?
- 如何实现xp开机的用户切换界面
- winform DataGridview 可否可以做成折叠的效果“?
- 请进:多层结构与Web服务的讨论
- 请教如何用反射获取listView.Items集合中的某项?
- 如何让菜单项与工具栏按钮对应?(在线急等)
- 大家有没有用过ComponentOne控件
ToBoolean(byte[] value,int startIndex);
ToChar(byte[] value,int startIndex);
ToDouble(byte[] value,int startIndex);
ToInt16(byte[] value,int startIndex);
ToInt32(byte[] value,int startIndex);
ToInt64(byte[] value,int startIndex);
ToSingle(byte[] value,int startIndex);
ToString(byte[] value);
ToString(byte[] value,int startIndex);
ToString(byte[] value,int startIndex,int length);
ToUInt16(byte[] value,int startIndex);
ToUInt32(byte[] value,int startIndex);
ToUInt64(byte[] value,int startIndex); 如果是结构的话,序列化是最直接的方式,如果不能序列化,那只能自己定义转换的方式了,.net没有提供直接转换的方式。可以根据基本类型的转换来转换结构。
public struct float1
{
float a;
float b;
public float1(float c,float d)
{
a=c;
b=d;
}
}
float1 testfloat= new float1(20.1f,23.2f);这个结构可以直接转换么?如果不行,如何用其他的方法转换?
byte[] bbytes = BitConverter.GetBytes(testfloat.b);
byte[] bytes = new byte[abytes.Length + bbytes.Length];
Buffer.BlockCopy(abytes, 0, bytes, 0, abytes.Length);
Buffer.BlockCopy(bbytes, 0, bytes, abytes.Length, bbytes.Length);
bytes就是转换后的结果。
上班时间不能上oicq,但是希望能和你email联系,没有分给的朋友你要不要呀?
MemoryStream ms = new MemoryStream();
InfoStruct info = new InfoStruct();
info.flag = "login";
info.parameter1 = account;
info.parameter2 = pwd;
bf.Serialize(ms, info);
byte[] byteData = ms.ToArray();