Reputation: 1
I have created an application that will save lists to a .dat file using a binary formatter and serializing the list.
I wish to then de serialize this list and display this within a text box.
Furthermore, I have tried using a for each loop to get every object from the list, but it won't continue through the rest of the lists and stops at the first list stored within the file.
I have been tasked with binary formatter even though Ive been informed its obsolete.
Upvotes: 0
Views: 150
Reputation: 7440
give this a try:
var totalList = new List<InPerson>();
do
{
var subList = (List<InPerson>)bFormatter.Deserialize(inFile);
totalList.AddRange(subList);
} while (!inFile.EndOfStream);
foreach (InPerson a in totalList)
txtBookings.Text += a.ToString();
//maybe set InPersonLIst to totalList
InPersonList = totalList;
This assumes that instead of 1 list with many items, there are many lists with many items.
This structure seems odd to say the least, you should consider having 1 list with many items.
Upvotes: 1