Сортировка по второму значению внутри строки - C#
Формулировка задачи:
У меня есть проект и таблица результатов которую нужно отсортировать по 2 полю, а именно по числу, короч игра тетрис, такая сортировка не работает, чего не хватает?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gamelogic.tetrisobjects
{
public class TableResults
{
public static string GameName = "";
public static string Name = "";
static int count = 0;
public static void addResults(string Scope)
{
using (StreamWriter writer = new StreamWriter("tableresults.txt", true))
{
writer.WriteLine("{0}#{1}",Name,Scope);
}
}
public static List<string> readResult()
{
List<string> res = new List<string>();
using (StreamReader reader = new StreamReader("tableresults.txt"))
{
string str;
while ((str = reader.ReadLine()) != null)
{
var strs = str.Split('#').ToArray();
if (strs.Length > 1)
res.Add(String.Format("{0} {1}", strs[0], strs[1]));
count++;
}
}
res.Sort();
res.Reverse();
return res;
}Решение задачи: «Сортировка по второму значению внутри строки»
textual
Листинг программы
public static List<string> readResult()
{
List<ResultData> tmpRes = new List<ResultData>();
List<string> res = new List<string>();
using (StreamReader reader = new StreamReader("tableresults.txt"))
{
string str;
while ((str = reader.ReadLine()) != null)
{
var strs = str.Split('#').ToArray();
if (strs.Length > 1)
tmpRes.Add(new ResultData(strs[0], int.Parse(strs[1])));
count++;
}
}
tmpRes = tmpRes.OrderByDescending(x => x.Score).ToList();
foreach (ResultData data in tmpRes)
res.Add(data.ToString());
return res;
}