C# Object Binary Serialization

前端 未结 6 1735
-上瘾入骨i
-上瘾入骨i 2020-12-05 02:17

I want to make a binary serialize of an object and the result to save it in a database.

Person person = new Person();
person.Name = \"something\";

MemoryStr         


        
6条回答
  •  囚心锁ツ
    2020-12-05 03:03

    I used something like this

    MemoryStream memoryStream = new MemoryStream();
    BinaryFormatter binaryFormatter = new BinaryFormatter();
    binaryFormatter.Serialize(memoryStream, Person);
    memoryStream.Flush();
    memoryStream.Position = 0;
    string value = Convert.ToBase64String(memoryStream.ToArray());
    

提交回复
热议问题