C# how to save List<Panel> to file

122 Views Asked by At

so I've got two lists

public List<Panel> allPanels = new List<Panel>();
public List<Panel> displayedPanels = new List<Panel>();

and I'm trying to save both lists in a file (foreach list separate file). Also I want to be able to read from the files.

What I tried so far was this:

FileStream stream = new FileStream(@"allPanels.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, allPanels);
stream.Close();  

But it didnt quit work out because the class "Panel" isn't serializable. How can I save the two lists to a file, be able to read from the files and get the data back to the lists?

Thanks for help.

0

There are 0 best solutions below