Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Serialization 转换列表<;int>;到字节[]_Serialization_.net 2.0_Bytearray - Fatal编程技术网

Serialization 转换列表<;int>;到字节[]

Serialization 转换列表<;int>;到字节[],serialization,.net-2.0,bytearray,Serialization,.net 2.0,Bytearray,在.NET2.0中是否有一个API可以让我快速地将整数列表转换为字节数组(list到byte[])?生成的字节数组应该是整数值序列的按位二进制表示,因此使用默认的.NET类型序列化来序列化列表实例将不起作用。List intList=new List(); List<int> intList = new List<int>(); int[] intArray = intList.ToArray(); byte[] byteArray = new byte[intArray

在.NET2.0中是否有一个API可以让我快速地将整数列表转换为字节数组(
list
byte[]
)?生成的字节数组应该是整数值序列的按位二进制表示,因此使用默认的.NET类型序列化来序列化列表实例将不起作用。

List intList=new List();
List<int> intList = new List<int>();
int[] intArray = intList.ToArray();
byte[] byteArray = new byte[intArray.Length*4];
Buffer.BlockCopy(intArray, 0, byteArray, 0, byteArray.Length);
int[]intArray=intList.ToArray(); byte[]byteArray=新字节[intArray.Length*4]; 块复制(intArray,0,byteArray,0,byteArray.Length);
使用原始内存地址而不是数组索引来复制数组数据。它只适用于原语数组。

List intList=new List();
int[]intArray=intList.ToArray();
byte[]byteArray=新字节[intArray.Length*4];
块复制(intArray,0,byteArray,0,byteArray.Length);

使用原始内存地址而不是数组索引来复制数组数据。它只适用于原语数组。

在什么上下文中序列化?自动地作为二进制序列化/ XML序列化的一部分-或其他什么,或手动?也,您考虑了EndiaNess吗?@ OnDRJ Chandiess在我的情况下并不重要。重要的是字节数组包含(仅)相同顺序的整数中的所有位。在这种情况下,我认为@thecoop提供了一个很好的解决方案。在什么上下文中序列化?自动地作为二进制序列化/ XML序列化的一部分-或其他什么,或手动?也,您考虑了EndiaNess吗?@ OnDRJ Chandiess在我的情况下并不重要。重要的是字节数组包含(仅)相同顺序的整数中的所有位。在这种情况下,我认为@thecoop提供了一个很好的解决方案。