int SortFun(name_time x, name_time y) { if (x.time < y.time) { return(-1); } if (x.time == y.time) { return(0); } if (x.time > y.time) { return(1); } else { return(0); } }
void Read_Best() { string path1 = base_path + "/Best/Легкая.txt"; string path2 = base_path + "/Best/Средняя.txt"; string path3 = base_path + "/Best/Тяжелая.txt"; string[] phs = new string[] { path1, path2, path3 }; StackPanel[] sps = new StackPanel[] { eazy_panel, med_panel, hard_panel }; for (int i = 0; i < 3; i++) { using (System.IO.StreamReader sw = new System.IO.StreamReader(phs[i])) { List <name_time> list = new List <name_time>(); string line; while ((line = sw.ReadLine()) != null) { if (line == "") { break; } name_time new_best = new name_time(); string[] split = line.Split(';'); new_best.name = split[0]; new_best.time = Convert.ToInt32(split[1]); list.Add(new_best); } list.Sort(SortFun); foreach (name_time element in list) { Label new_best = new Label(); new_best.Content = element.name + " за " + Convert.ToString(element.time) + " секунд"; new_best.HorizontalContentAlignment = HorizontalAlignment.Center; sps[i].Children.Add(new_best); } } } }