Я пытаюсь поместить десятки моих лидеров в порядок от наивысшего до самого низкого. Я не уверен, как я это сделаю, я знаю, что это не место, чтобы попросить написать код, но я везде искал, мне нужно создать массив или список или класс?Лидер рейтинга
namespace Coursework___Quiz
{
public partial class frmFinal : Form
{
public frmFinal()
{
InitializeComponent();
}
private void frmFinal_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void frmFinal_Load(object sender, EventArgs e)
{
//sets the leaderboard equal to the file scoreInfo
rchBxScores.Text = File.ReadAllText(".\\scoreInfo.bin");
//sets a textbox equal to the players score
rchBxScore.Text = Convert.ToString(scoresClass.score);
//reads the first line of the file InputInfo and sets a string equal to it
string nameScore = File.ReadAllLines(".\\InputInfo.bin").Skip(0).Take(1).First();
//sets a textbox equal to the string nameScore
rchBxNameScore.Text = nameScore;
//reads the second line of the file InputInfo and sets a string equal to it
string quizScore = File.ReadAllLines(".\\InputInfo.bin").Skip(1).Take(1).First();
//sets a textbox equal to the string quizScore
rchBxQuizNameScore.Text = quizScore;
}
private void btnClearScores_Click(object sender, EventArgs e)
{
//opens the file scoreInfo
FileStream fileStream = File.Open(".\\scoreInfo.bin", FileMode.Open);
//empties the file
fileStream.SetLength(0);
//closes the file
fileStream.Close();
//sets the leaderbaord equal to the file
rchBxScores.Text = File.ReadAllText(".\\scoreInfo.bin");
}
//creates a bool variable and sets it equal to false
bool saved = false;
private void btnSaveScore_Click(object sender, EventArgs e)
{
//checks if saved equals false
if (saved == false)
{
//if saved equals false, it opens the file scoreInfo
using (StreamWriter scoreInfo = new StreamWriter(".\\scoreInfo.bin", true))
{
//adds the information from the textboxes to the file
scoreInfo.WriteLine(rchBxNameScore.Text + "\t" + rchBxQuizNameScore.Text + "\t" + rchBxScore.Text);
}
//clears all the players score details
rchBxNameScore.Clear();
rchBxQuizNameScore.Clear();
rchBxScore.Clear();
rchBxScores.Text = File.ReadAllText(".\\scoreInfo.bin");
//sets saved to true
saved = true;
}
}
}
}
В настоящее время оценки сохраняются по мере их ввода.
Сохраните результаты в массиве или 'List', а затем вы можете использовать' LINQ' и метод 'OrderByDescending'. –