public BestPlayersForm() { InitializeComponent(); bp = new BestPlayers(); Deserialize(); bp.bestPlayers = bp.bestPlayers.OrderByDescending(o => o.Points).ToList(); foreach (Player p in bp.bestPlayers) { ListViewItem lv = new ListViewItem(p.Name); lv.SubItems.Add(p.Points.ToString()); lv.SubItems.Add(p.Date.ToShortDateString()); listView1.Items.Add(lv); } }
public void Deserialize() { string dataFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\DataFile.dat"; if (File.Exists(dataFile)) { FileStream fs = new FileStream(dataFile, FileMode.Open); try { BinaryFormatter formatter = new BinaryFormatter(); bp = (BestPlayers)formatter.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } } }