Serialization of Queue type not working

Posted by Soham on Stack Overflow See other posts from Stack Overflow or by Soham
Published on 2010-04-21T03:20:24Z Indexed on 2010/04/21 3:33 UTC
Read the original article Hit count: 215

Filed under:

Consider this piece of code:

private Queue Date=new Queue();
//other declarations
public DateTime _Date { 
 get { return (DateTime)Date.Peek();} 
 set { Date.Enqueue(value); } 
 }
 //other properties and stuff....
 public void UpdatePosition(...) 
 {
   //other code

    IFormatter formatter = new BinaryFormatter();
    Stream Datestream = new MemoryStream();
    formatter.Serialize(Datestream, Date);
    byte[] Datebin = new byte[2048];
    Datestream.Read(Datebin,0,2048);
    //Debug-Bug
    Console.WriteLine(Convert.ToString(this._Date));
    Console.WriteLine(BitConverter.ToString(Datebin, 0, 3));

    //other code
 }

The output of the first WriteLine is perfect. I.e to check if really the Queue is initialised or not. It is. The right variables are stored etc. (I inserted a value in that Queue, that part of the code is not shown.)

But the second WriteLine is not giving the right expected answer: It serializes the entire Queue to 00-00-00.

© Stack Overflow or respective owner

Related posts about c#