مرتب کردن نوشته های درون یک فایل
کد:
StreamReader sr = new StreamReader("text.txt");
string str = sr.ReadToEnd();
string[] split = str.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
List<string> players=new List<string>();
List<int> scores=new List<int>();
foreach (string temp in split)
{
string[] spliter = temp.Split('=');
players.Add(spliter[0]);
scores.Add(int.Parse(spliter[1]));
}
scores.Sort((x, y) => y.CompareTo(x));
sr.Close();
StreamWriter sw = new StreamWriter("text.txt");
int count=0;
foreach(string temp in players){
sw.Write(temp+"=");
sw.Write(scores[count]);
sw.Write("\r\n");
count++;
}
sw.Close();