Managing Student Enrollments Using C# Dictionary and HashSet

In this lesson, we'll learn how to manage student enrollments using C#'s Dictionary and HashSet collections. These data structures allow efficient data organization and access, which are essential for building an enrollment system. We'll implement methods to handle enrolling and unenrolling students, checking enrollment status, and listing students in a course. This practical approach will enhance your understanding of these advanced structures. Now, let's dive into the methods we need to implement.

Introducing Methods to Implement

Here are the methods we need to implement in our enrollment system:

  • Enroll(string student, string course): This method adds a student to a course. If the student is already enrolled, it does nothing.
  • Unenroll(string student, string course): This method removes a student from a course. It returns true if the student was enrolled and has now been removed. Otherwise, it returns false. If, after unenrolling the student, the course becomes empty (no one is enrolled there), remove the course as well.
  • IsEnrolled(string student, string course): This method checks if a student is enrolled in a course. It returns true if the student is enrolled and false otherwise.
  • ListStudents(string course): This method returns a of all students enrolled in a given course. If no students are enrolled, it returns an empty .
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal