Class Test
{
Int ID;
String name;
Char [] chars = "ABCD". tochararray ();
}
Declared as serializable:
[Serializable]
Class Test
{
Int ID;
String name;
Char [] chars = "ABCD". tochararray ();
}
Then, in the conversion area:
Memorystream stream = new memorystream ();
Iformatter formatter = new binaryformatter ();
Test T = new test ();
Formatter. serialize (stream, t );
Stream. Flush ();
Byte [] thebytes = stream. toarray ();
Stream. Close ();
// Thebytes is the serialized byte array
Deserialization:
Iformatter formatter = new binaryformatter ();
Memorystream stream = new memorystream (thebytes); // thebytes is the serialized result
Test t = (TEST) formatter. deserialize (fromstream );
Stream. Close ();
// T is the deserialized object.
In addition, to use the above classes, you need to reference:
Using system. IO;
Using system. runtime. serialization;
Using system. runtime. serialization. formatters. Binary;