public static void Serialize(Scoreinfo score) { try { using (Stream stream = File.Open("Scoreboard.bin", FileMode.Create)) { BinaryFormatter bin = new BinaryFormatter(); listOfAllScores.Add(score); bin.Serialize(stream, listOfAllScores); } } catch (IOException) { MessageBox.Show("Error, can't serialize to file."); } }
public static void writeScore(Scoreinfo score) { Serialize(score); EntryWindow.listBox.Items.Clear(); sortScore(); foreach (Scoreinfo element in listOfAllScores) { if (EntryWindow.listBox.Items.Count == 10) { break; } EntryWindow.listBox.Items.Add(element); } }