Class serialization and java class serialization
Class Program {static void Main (string [] args) {A = new a () {AppId = "4", haor = "Haoran"}; var bytes =. objectToBytes (a); var classA =. bytesToObject (bytes); Console. readKey ();} [Serializable ()] public abstract class PacketBase {public string AppId {get; set;} public string Token {get; set;} public string DeviceId {get; set ;}} [Serializable ()] public class A: PacketBase {public string haor {get; set ;}/// <summary> /// serialize an object, returns a byte [] /// </summary> /// <param name = "obj"> serializable object </param> /// <returns> </returns> public byte [] ObjectToBytes (object obj) {using (MemoryStream MS = new MemoryStream () {IFormatter formatter = new BinaryFormatter (); formatter. serialized (ms, obj); return ms. getBuffer ();}} /// <summary> /// restore a serialized byte [] array /// </summary> /// <param name = "Bytes"> </param >/// <returns> </returns> public object BytesToObject (byte [] Bytes) {using (MemoryStream MS = new MemoryStream (Bytes) {IFormatter formatter = new BinaryFormatter (); return formatter. deserialize (MS );}}}}