How to remember data after the program is closed?
I'm making a high score list, so I need to store the names of players that achieved the highest score.
Basicaly, you would enter your name (ok, this is easy), your name is saved, you exit the program, and when you run the program next time, your name will still be on the list?
How can I do this?
Re: How to remember data after the program is closed?
There are lots of ways to save data:
-using Settings
-write the data to files, and then read it
-save the data in a Database
In your case (highscore), writing to top scores to a file (either a simple txt file or an xml file) seems like the best option.
Here's a quick guide that teaches how to read and write to files:
http://www.csharp-station.com/HowTo/...eTextFile.aspx
1 Attachment(s)
Re: How to remember data after the program is closed?
Thanks for the fast reply.
So ok, I've created the txt file within the project, and I can't open it with the stream reader command cause I can't find the right path to the file. Here is a pic of it's location.
My question is:
StreamReader sr = new StreamReader(WHAT SHOULD I PUT HERE);
Re: How to remember data after the program is closed?
You don't need to create the file in advance, just create the file in the code.
In fact, you don't need to do anything different, because the StreamWriter class creates an empty file if the file (in the path you passed to it as a constructor argument) doesn't exist.
Re: How to remember data after the program is closed?