Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a leaderboard, and I'm going to have the scores saved in a (.txt) document since I'm not yet familiar with implementing database systems.

I have done this before in Java, using Scanner and PrintWriter. However, I am completely clueless about how I will be able to do that in C#.

The information that will be stored in the document are only the names and scores of the players.
Posted
Comments
BillWoodruff 27-Sep-14 6:16am    
Since you specify saving the data in a .txt file, I assume you want the document content to have a specific "human readable format:" correct ?

Have you looked into how you create a file, and write to it, in C# ?
kmllev 27-Sep-14 10:21am    
I have .txt file ready, just waiting for scores to be written on it.

I have done it before like this (in the .txt document):
John 25
Peter 20
Warren 23

I've tried looking around again and I have a slight idea of one possible way to do it: StreamReader/Writer? But with Java, I didn't have much difficulty reading the string and int values because Java has methods for that, but based on what I've been reading so far, it'd be quite a difficult task to achieve in C#.

P.S. I don't really need to create the .txt file from code, I'd just need to load it or read its content then after sorting out the scores, append them to the .txt file.

See .NET Book Zero[^] for tutorials and sample code that will help you.
 
Share this answer
 
It's extremely easy to open, read, and write text files in C#. There are good examples on-line (even ... gasp ... from Microsoft):

Start here:
http://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.100).aspx

read:
http://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.110).aspx

write:
http://msdn.microsoft.com/en-us/library/6ka1wd3w(v=vs.100).aspx

Read, study, experiment, write code, debug, observe, analyze: repeat until done :)
 
Share this answer
 
Comments
kmllev 28-Sep-14 3:37am    
Thank you, Bill! Actually I am a little embarrassed right now, realizing it IS easy to find the answers myself, just that I didn't have the right keywords back then. Thank you!

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