I need to compare the name of the object (test) with the name of the test that has been queued. The logic that I have is to use the foreach loop, so for each test in the queue I can compare the name that the user provides with the name in each test, until I find a match (in which he will tell the user the grade they made in the test in the message box).
The code in the fragment is incomplete; using the presented tests with a getter does not work (does not give me the opportunity to do this in intellisense).
This happens in the btnFindTest_Click method. This is the code that I still have:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConsoleApplication1
{
public partial class Form1 : Form
{
Queue submittedTest = new Queue();
Stack outForChecking = new Stack();
public Form1()
{
InitializeComponent();
}
private void btnSubmitTest_Click(object sender, EventArgs e)
{
Random rdm = new Random();
int testScore = rdm.Next(0, 100);
string score = testScore.ToString();
string name = txtName.Text;
Test tests = new Test(name, score);
label3.Text = String.Format("{0}", name);
submittedTest.Enqueue(tests);
listSubTests.Items.Add(new Test(name, score));
txtName.Clear();
}
private void btnFindTest_Click(object sender, EventArgs e)
{
string compareName = "";
string tempName = txtName.Text;
foreach (Test tests in submittedTest)
{
if (compareName == tempName)
{
System.Windows.Forms.MessageBox.Show("Your score was --");
}
}
}
public void txtName_TextChanged(object sender, EventArgs e)
{
}
private void txtScore_TextChanged(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
Close();
}
}
}
And the test object is defined in it by its own class here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Test
{
private string name;
private string score;
public string Name
{
get { return name; }
set { name = value; }
}
public string Score
{
get { return score; }
set { score = value; }
}
public Test(string name, string score)
{
this.name = name;
this.score = score;
}
public override string ToString()
{
return (String.Format("{0} {1} ", name, score));
}
}
}
Once again, I am not familiar with C #, and this project is for school, so if I'm far away, please let me know!