Hi,
I have the following class:
The following code calls the Serialize method:Code:[Serializable()] class Class1 { private int a; private int b; private int[] c; public int Init () { a = 5; b = 6; c = new int[3]; c[0] = 1; return 0; } public byte[] Serialize() { BinaryFormatter bin = new BinaryFormatter(); MemoryStream mem = new MemoryStream(); bin.Serialize(mem, this); return mem.GetBuffer(); } }
But buffer does not contains only the data but also information for the deserialize process. I do not need it.Code:namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Class1 c= new Class1(); c.Init (); byte[] buffer = c.Serialize(); } } }
How can I write a "non default" Serialize that will do the work ?
Can I avoid unsafe code for this purpose ?
The exact size of data that must be sent is 2x4 + 3x4 = 20 bytes;
Thanks.




Reply With Quote