Serialization of Queue type not working
- by Soham
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.