I'm making an attempt at looping through Course objects and displaying them to the console. For some reason however my solution doesn't seem to work, can anyone detect any obvious issues that I might be the cause for this? thanks :)
class Course
{
private int v1;
private string v2;
private string v3;
private int v4;
public Course(int v1, string v2, string v3, int v4)
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
}
public int courseCode { get; set; }
public string courseName { get; set; }
public string professor { get; set; }
public int capacity { get; set; }
}
class Computation
{
public static List<Course> courses = new List<Course>();
public static void addCourse(Course c)
{
courses.Add(c);
}
public static void viewCourses()
{
foreach(var c in courses)
{
Console.WriteLine(c.courseName);
}
}
}
Main
static void Main(string[] args)
{
Course computerScience = new Course(1, "Computer Science", "Dr Shkhla", 200);
Course mathematics = new Course(2, "Mathematics", "Dr Shkhla", 200);
Course physics = new Course(3, "Physics", "Dr Shkhla", 200);
addCourse(computerScience);
addCourse(mathematics);
addCourse(physics);
viewCourses();
}