Normally we do not do your homework.
But you showed us what you already achieved.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace LM
{
class Program
{
static void Main(string[] args)
{
var students = new List<Student>();
var newStudent1 = new Student();
newStudent1.Id = 0;
newStudent1.Name = "Bob";
newStudent1.DateOfBirth = DateTime.Now;
newStudent1.IsEnrolled = false;
newStudent1.Courses.Add("Mathematics");
newStudent1.Courses.Add("Programming");
var newStudent2 = new Student(1, "Maria", DateTime.Now, true);
var newStudent3 = new Student
{
Id = 2,
Name = "John",
DateOfBirth = DateTime.Now,
IsEnrolled = false
};
students.Add(newStudent1);
students.Add(newStudent2);
students.Add(newStudent3);
var choice = "";
while (choice != "0")
{
Console.WriteLine("Choose an option:");
Console.WriteLine("1: List all students");
Console.WriteLine("2: Add student");
Console.WriteLine("3: Remove student");
Console.WriteLine("0: Exit");
Console.WriteLine("---------------------------------------------");
choice = Console.ReadLine();
switch (choice)
{
case "1":
foreach (var s in students)
{
Console.WriteLine(s.Id + "\t" + s.Name);
}
Console.WriteLine("Type ID for details. x for Exit");
string detailsChoice = Console.ReadLine();
switch (choice)
{
case "x":
break;
default:
var results = from x in students
where x.Id.ToString() == detailsChoice
select x;
var selectedStudent = results.FirstOrDefault();
Console.WriteLine(selectedStudent.Id);
Console.WriteLine(selectedStudent.Name);
Console.WriteLine(selectedStudent.DateOfBirth.ToShortDateString());
Console.WriteLine(selectedStudent.IsEnrolled.ToString());
foreach(string course in selectedStudent.Courses)
{
Console.WriteLine(course);
}
break;
}
break;
case "2":
break;
case "3":
break;
default:
break;
}
}
}
}
}
Student.cs
using System;
using System.Collections.Generic;
namespace LM
{
class Student
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime DateOfBirth { get; set; }
public bool IsEnrolled { get; set; }
public List<string> Courses { get; set; }
public Student()
{
Courses = new List<string>();
}
public Student(int id, string name, DateTime dob, bool enrolled)
{
Id = id;
Name = name;
DateOfBirth = dob;
IsEnrolled = enrolled;
}
public void Register(string course)
{
Courses.Add(course);
}
public void Drop(string course)
{
Courses.Remove(course);
}
}
}</string></string>
Let me also give some hints:
In Students.cs you should use
Courses = new List<string>();</string>
Moreover the switch statement in Program.cs also needs a default value.