我有两种列表:一个带有 int 元素的列表和另一个带有 bool 元素的列表。要将这些列表传递给服务器,我必须执行以下操作:
using(MemoryStream m = new MemoryStream()){
using(BinaryWriter writer = new BinaryWriter(m)){
byte[] bytesIntList = new byte[IntList.Count * sizeof(int)];
Buffer.BlockCopy(IntList.ToArray(), 0, bytesIntList, 0, bytesIntList.Length);
writer.Write(Convert.ToBase64String(bytesIntList));
byte[] bytesBoolList = new byte[BoolList.Count * sizeof(bool)];
Buffer.BlockCopy(BoolList.ToArray(), 0, bytesBoolList, 0, bytesBoolList.Length);
writer.Write(Convert.ToBase64String(bytesBoolList));
}
byte[] data = m.ToArray();
return data;
}
现在,我想知道如何执行相反的过程:接收这些列表:
using (MemoryStream m = new MemoryStream(data)){
using (BinaryReader reader = new BinaryReader(m)){
byte[] bytesIntList = Convert.FromBase64String(reader.ReadString());
byte[] bytesBoolList = Convert.FromBase64String(reader.ReadString());
List<int> newIntList = ??? //what do I have to do here?
List<bool> newBoolList = ??? //what do I have to do here?
}
}
如果您有其他通过列表的建议,我们将不胜感激!