小编Tal*_*Bin的帖子

对象到字节的转换

当我试图将一个对象转换为字节数组时,我得到了一个奇怪的数组.这是代码:

        using (MemoryStream ms = new MemoryStream())
        {
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, obj);
            Console.WriteLine(ByteArrayToString(ms.ToArray()));
        }
//int obj = 50;

//string ByteArrayToString(byte[] byteArr) the functionality of this method is pretty obvious
Run Code Online (Sandbox Code Playgroud)

结果是这样的:

"00 01 00 00 00 FF FF FF FF 01 00 00 00 00 00 00 04 01 00 00 00 0C 53 79 73 74 65 6D 2E 49 6E 74 33 32 01 00 00 00 07 6D 5F 76 61 6C 75 65 00 …

.net c# conventions

1
推荐指数
1
解决办法
1523
查看次数

标签 统计

.net ×1

c# ×1

conventions ×1