First you have to get a class or structure for storing information about the player, for example:
struct PlayerInfo { public string Name; public int Score; }
In the simplest case, there will be enough structure, but it can be transformed at any time into a full-fledged class, and at the same time we can figure out how the .NET structures differ from the classes (they have already answered this question more than once).
Next, create a repository for our records,
List<PlayerInfo>() recordTable = new List<PlayerInfo>();
Perfect for this purpose.
In the course of the program, we edit our List as a normal array, at the beginning of the program we load values from the file into it, at the end we upload to the file.
For storage on disk, a simple text format is suitable in which one line stores information about one player, and the values are separated by a semicolon, a la .csv , for example: "Вася Пупкин;100500" . Subsequently, you can modify to a full. .csv or more complex format. You should not immediately take up XML, and for such a simple case it is clearly redundant, or the author does not agree on something =)
It remains to implement the preservation and loading of the table of records, in the proposed version with a text format, everything is done line by line reading and writing to the file, how to do it in the official documentation on MSDN, on this and many other resources, therefore, without details.
For convenience, you can add methods to the structure / class for convenient conversion of values:
public void SetFromCsv(string csvStr) { string[] fields = csvStr.Split(';'); Name = fields[0]; Score = int.Parse(fields[1]); } public string GetCsvString() { return string.Format("{0};{1}", Name, Score); }
If you still really want XML, then look towards using XDocument and / or XElement . They have built-in tools for loading and saving xml files simply by specifying the full name of the desired file. However, I note that sorting the nodes inside XElement.Nodes , unlike the List , cannot be accomplished with a single line of code, only by hand, deleting and creating the nodes in the required order. Therefore, it makes sense to use XML only for storage and loading, and all other actions to be performed on the List .