Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey guys please help,am creating a game in C# windows application the aim of the game is to make all the buttons red so if all the buttons are red a form is displayed asking for the player's name,so the name entered by the player should be displayed when the other called top score is clicked on the main interface of the game.all i know is that a txt file has to be created and the name will be stored on it then for the name to displayed on another form it will be taken from the same file but i dont know how to go about that..

The simplest way (not the most efficient, but certainly the easiest for a beginner) would be
string[] lines = File.ReadAllLines(@"F:\Temp\NamesFile.txt");

File.WriteAllLines(@"F:\Temp\NamesFile.txt", lines);
All you have to do is modify the lines array between the two statements!
Share this answer
You'll want to use the classes TextReader and TextWriter.

There is an example here at MSDN[^]
Share this answer
Share this answer
Member 8168059 1-Sep-11 12:14pm    
Thanks for the reference....
Abhinav S 2-Sep-11 2:14am    
You are welcome.
You can vote for all answers that helped.
You could also very easily use a database for this. Have you considered a DB solution?
Share this answer
It might help,

How to: Read Text from a File

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900