Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:59+00:00 2026-06-18T08:05:59+00:00

I have a small problem here. I have an array which holds some objects

  • 0

I have a small problem here.
I have an array which holds some objects (which have properties, duh)
Now I want to sort them by an int property that they have. My qustion is not how to sort them, but how do I read the value of the property of the objects in the array?

private void WriteHighscoreToFile(int groesse, int minenAnzahl, int zeit, string name)
{
  using (StreamWriter sw = new StreamWriter(@"C:\Users\tstadler\Desktop\Highscore.txt", true))
  {
    sw.WriteLine("Spieler: " + name + " Punkte: " + (groesse * minenAnzahl - zeit * 2) + " Groesse: " + groesse + " Minenanzahl " + minenAnzahl + " Zeit: " + zeit);
  }

  using (StreamReader sr = new StreamReader(@"C:\Users\tstadler\Desktop\Highscore.txt", true))
  {
    List<CreateNewHighscore> highScores = new List<CreateNewHighscore>();
    while (sr.ReadLine() != null)
    {
      _objectProperties = sr.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
      highScores.Add(new CreateNewHighscore(_objectProperties));
      highscoreCount++;
    }
    _highscoresArray = highScores.ToArray();
    vergleicheArray(_highscoresArray);
  }
}

The Class:

    public class CreateNewHighscore
      {
        public string _name;
        public int _punkte;
        public int _groesse;
        public int _minenAnzahl;
        public int _zeit;


     public CreateNewHighscore(string[] infos)
     {
       _name = infos[1];
       _punkte = int.Parse(infos[5]) * int.Parse(infos[7]) - 2 * int.Parse(infos[9]);
       _groesse = int.Parse(infos[5]);
       _minenAnzahl = int.Parse(infos[7]);
       _zeit = int.Parse(infos[9]);
     }   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:06:00+00:00Added an answer on June 18, 2026 at 8:06 am

    My qustion is not how to sort them, but how do I read the value of the property of the objects in the array?

    You expose it as a property; for example:

    class CreateNewHighscore
    {
        string _name;
        int _punkte, _groesse, _minenAnzahl, _zeit;
        public string Name { get { return _name; } }
        public int Punkte { get { return _punkte; } }
        public int Groesse { get { return _groesse; } }
        public int Zeit { get { return _zeit; } }
        public int MinenAnzahl { get { return _minenAnzahl; } }
    
        // constructor not shown
    }
    

    Then you can access that member from any array / list; for example:

    highScores.Sort((x,y) => x.Punkte.CompareTo(y.Punkte));
    

    or:

    int firstPunkte = _highscoresArray[0].Punkte;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a small problem here which i cannot fix,This post goes through but
So here is our problem: We have a small team of developers with their
Here's the problem -- I have a few thousand small text snippets, anywhere from
Here a small piece of code for testing and explain the problem. I have
I have a small problem which i can't seem to figure out. I tried
I have a small problem which i can't seem to solve myself. Look at
I have a small problem. I am working with some manual testers who are
I have a script that performs some simple editing which works fine, the problem
I have got a small problem with 1D array in c++. I have got
have small problem, and would very much appreciate help :) I should convert byte

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.