I'm having a hard time understanding the need for the ISerializable interface... I guess I'm missing something pretty important in this subject, so I'd appreciate it if somebody could give me a hand.
This works perfectly well -
[Serializable]
class Student
{
public int age;
public string name;
public Student()
{
age = 0;
name = null;
}
}
class Program
{
public static void Main()
{
Stream stream = File.Open("Test123.txt", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
Student s1 = new Student();
s1.name = "Peter";
s1.age = 50;
bf.Serialize(stream, s1);
stream.Close();
Stream stream2 = File.Open("Test123.txt", FileMode.Open);
Student s2 = (Student)bf.Deserialize(stream2);
Console.WriteLine(s2.age);
}
And it worked without implementing ISerializable and without overriding GetObjectData(). How so? What is the use of the interface then?
Thanks.