I have a class library that has two constructor. The first constructor accepts two arguments and the second accepts three. Below is my class library code. Easier to put the code than try to explain it.
public class Student
{
public string name;
public string course;
public MyDate bday;
public Student(string name, string course)
{
this.name = name;
this.course = course;
}
public Student(string name, string course, MyDate bday)
{
this.name = name;
this.course = course;
this.bday = bday;
}
The MyDate library has another constructor that accepts three arguments which would be the date, month and year of the birthday. Now I have a form which contains 3 listbox and on the third listbox I will be displaying the birthdays. I declare the birthdays in the code (just like i showed below) now I'm having problem on how to display it.
MyDate[] bd = new MyDate[5] { new MyDate(29, 3, 1990),
new MyDate(30, 1, 1988),
new MyDate(9, 6, 1987),
new MyDate(2, 4, 1989),
new MyDate(17, 8, 1986),
};
Student[] s = new Student[5] { new Student("John", "BSCS"),
new Student("Paul", "BSIT"),
new Student("George", "BSCP"),
new Student("Jane", "BSCS"),
new Student("May", "BSIT")
};
Can anyone please tell me how i should do this? I tried this Student[] s = new Student[5] { new Student("John", "BSCS", bd[0]) and so on but it gives me error. I know this is a beginners question and I am a beginner. Thank you.
Edit: The initialization was done in the form1.cs.
bd[0]in your field initializer. Move it into the constructor.