sceed
sceed

Reputation: 11

C# Create high score text file

I'm creating a little game (Memory) that should contain a high score list. The project is a windows grid app using XAML and C#. This is the last solution I saw and it sounds logical to me:

private void New_Score(int score, string name)
{
    string filename = "highscore.txt";
    List<string> scoreList;
    if (StorageFile.Exists(filename))
        scoreList = File.ReadAllLines(filename).ToList();
    else
        scoreList = new List<string>();
    scoreList.Add(name + " " + score.ToString());
    var sortedScoreList = scoreList.OrderByDescending(ss => int.Parse(ss.Substring(ss.LastIndexOf(" ") + 1)));
    File.WriteAllLines(filename, sortedScoreList.ToArray());
}

If I try this in my window8 project. The File class is not found.

I'm searching for hours but I can't find a solution that fits for me.

Upvotes: 1

Views: 697

Answers (1)

SQL Police
SQL Police

Reputation: 4196

The File class is in System.IO namespace.

Therefore, on top of your file, add this reference:

using System.IO;

Upvotes: 2

Related Questions