this can probably be done with a foreach loop. However.. while / for should also work. If I have a class MyClass, and writes 100 objects of MyClass. How can I stop at end of file when i Deserialize? Thanks in Advance
FileStream inStr = new FileStream(@"file.dat", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
MyClass myclass = new MyClass();
while (???) // What to put here? EOF / End of stream check
{
myclass = (MyClass)bf.Deserialize(inStr);
//...
}
If you want to save and load a list of your
MyClasswhy not save a List object.Save
Load