private void High_score(object sender, RoutedEventArgs e) { CsvHelper csvHelper = new CsvHelper(); List <Score> scores = csvHelper.ReadCsv(); List <Score> highScore = scores.Where(x => x.Mode == (ModeCombobox.SelectedItem as Mode).Name).OrderBy(x => x.Time).ToList(); string Text = ""; if (highScore.ElementAtOrDefault(0) != null) { int ctr = 1; Text = "Mode: " + (ModeCombobox.SelectedItem as Mode).Name + "\n\n"; foreach (Score score in highScore) { Text = Text + "(" + ctr + ") is " + score.Time + "seconds!\n"; if (ctr >= 10) { break; } ctr++; } } else { Text = "Highscore for #" + (ModeCombobox.SelectedItem as Mode).Name + " is not set!"; } MessageBox.Show(Text); }
private void WriteScore(string mode, int time) { CsvHelper csvHelper = new CsvHelper(); List <Score> scores = csvHelper.ReadCsv(); scores.Add(new Score(mode, time)); csvHelper.WriteCsvFile(scores); }