Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

i have problem with my coding please help me to solve this

PrinzeDevilzPrinzeDevilz EarthMember Posts: 1

i want to sorted my score in my game
but i don't know how to sort this

this my code :

private void Highscore_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(Application.StartupPath + "\wall 1.jpg");
StreamReader myReader = new StreamReader(Application.StartupPath + "\data.txt");
while (!myReader.EndOfStream)
{
string [] score = myReader.ReadLine().Split(',');
label1.Text += score[0] + "\n";
label4.Text += score[1]+ "\n";
Array.Sort(score);

        }

    }

ex
:
in my txt
asa 180
adaq 200
wek 150

i want to make them like
adaq 200
asa 180
wek 150

Comments

  • SixtyHzSixtyHz USMember Posts: 13

    That looks like it will sort score in alphabetical order which means you should get the output you wrote. If you want it to actually sort the score you will have to sort on the numerical part of your string... you may need to construct a struct containing the name and the score and sort the array of structs by the score then print them out...

  • WiserWiser IsraelMember Posts: 6
    edited November 2015

    Hey,
    If I get it right, each time you read from the file you get a line with a name ("asa") and a score ("180") and put them in an array of strings called score which looks something like this:
    [0] = "asa", [1] = "180"

    What you do wrong is that you sort the array each time... that won't get you anywhere.
    What you want to do is put all the scores in the a list and sort it all together.

    :)
    If you put more code I can help you do it

  • Priyasha SarmahPriyasha Sarmah Member Posts: 14

    Construct a struct containing the name and the score and sort the array of structs by the score then print them out.
    For help, do visit : http://knowledgetpoint.com/csharp/introduction-to-oops/

Sign In or Register to comment.