Now it's time for some one regarding serialization:
Given this serializable class:
[Serializable]
public class Victim {
public static int InstanceCount;
public int Data { get; set; }
public Victim() {
InstanceCount++;
Data = 2;
}
}
and the following test code:
class Program {
static void Main(string[] args) {
Victim v = new Victim();
v.Data = 3;
BinaryFormatter serial = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
serial.Serialize(ms, v);
ms.Seek(0, SeekOrigin.Begin);
v = (Victim)serial.Deserialize(ms);
Console.WriteLine("Data {0}", v.Data);
Console.WriteLine("Instances {0}", Victim.InstanceCount);
}
}
What is the output, and why?
No comments:
Post a Comment