I have the following code:
public partial class Form1 : Form
{
const int MaxStudents = 4;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Student[] studentList;
studentList = new Student[4];
studentList[0] = new Student(51584, 17);
studentList[1] = new Student(51585, 19);
studentList[2] = new Student(51586, 15);
studentList[3] = new Student(51587, 20);
for (int i = 0; i < MaxStudents; i++)
{
lstStudents.Items.Add(studentList.ToString()[i]);
}
}
EDIT: In the Student class I have:
public Student(int id, int age) {
this.id = id;
this.age = age;
}
public override string ToString()
{
return string.Format("ID: {0} - Age: {1}", this.id, this.age);
}
Then in the form load I have:
private void Form1_Load(object sender, EventArgs e)
{
Student[] studentList;
studentList = new Student[4];
studentList[0] = new Student(51584, 17);
studentList[1] = new Student(51585, 19);
studentList[2] = new Student(51586, 15);
studentList[3] = new Student(51587, 20);
lstStudents.Items.AddRange(studentList);
}
I was wondering how I would output the parameters of each object in the array to the listbox. How would I make it so that each object is displayed in the listbox like so:
ID: 51584 - Age: 17
I'm not too sure how to basically convert the parameters into plain text to be listed in the listbox whilst adding additional text before the parameters (Like I did with 'id:', the hyphen and 'Age:')
Sorry for the long winded question but thought I'd explain as best as I can.