C# dictionary to bytes and bytes convert to dictionary
程序员文章站
2022-05-29 09:19:51
static byte[] GetBytesFromDic(Dictionary dic) { if(dic==null || !dic.Any()) { return null; } using (MemoryStream ms = new MemoryStream( ......
static byte[] getbytesfromdic(dictionary<string,string> dic) { if(dic==null || !dic.any()) { return null; } using (memorystream ms = new memorystream()) { binaryformatter binformatter = new binaryformatter(); binformatter.serialize(ms, dic); byte[] dicbytes = ms.toarray(); return dicbytes; } } static dictionary<string,string> getdicfrombytes(byte[] dicbytes) { dictionary<string, string> dic = new dictionary<string, string>(); using (memorystream ms = new memorystream(dicbytes)) { binaryformatter binformatter = new binaryformatter(); dic= (dictionary<string,string>) binformatter.deserialize(ms); } return dic; }
memorystream ms=new memorystream(bytes);
ms.toarray()
上一篇: 高德离线地图瓦片坐标偏移纠偏
下一篇: 哈密瓜甜吗?怎么才能挑到甜甜的哈密瓜?