Going Further Lesson 15 of 15
C# Final Project — Student Enrollment System
Build a complete console enrollment system in C# with records, a List and Dictionary, a menu, input validation, LINQ reports and saving to a CSV file.
In this final project you'll build a student enrollment system for a senior high school: enroll students into strands, list them, search, show reports with LINQ, and save everything to a CSV file. It uses nearly every topic in this course.
Features
- Enroll a student with an LRN (12 digits), name, grade level and strand.
- Refuse duplicate LRNs and invalid input.
- List all students, sorted by name.
- Search by part of a name.
- Report: number of students per strand and grade level.
- Save to and load from
enrollment.csv.
The code
Replace the contents of Program.cs with this, then dotnet run.
const string FilePath = "enrollment.csv";
string[] strands = { "STEM", "ABM", "HUMSS", "GAS", "TVL-ICT" };
var students = new Dictionary<string, Student>(); // key: LRN
Load();
while (true)
{
Console.WriteLine("\n=== ENROLLMENT SYSTEM ===");
Console.WriteLine("[1] Enroll [2] List [3] Search [4] Report [0] Save & exit");
switch (ReadInt("Choice: ", 0, 4))
{
case 1: Enroll(); break;
case 2: List(students.Values); break;
case 3: Search(); break;
case 4: Report(); break;
case 0: Save(); Console.WriteLine("Saved. Goodbye!"); return;
}
}
void Enroll()
{
string lrn = ReadText("LRN (12 digits): ");
if (lrn.Length != 12 || !lrn.All(char.IsDigit))
{
Console.WriteLine("Invalid LRN.");
return;
}
if (students.ContainsKey(lrn))
{
Console.WriteLine("That LRN is already enrolled.");
return;
}
string name = ReadText("Full name: ");
int grade = ReadInt("Grade level (11-12): ", 11, 12);
for (int i = 0; i < strands.Length; i++) Console.WriteLine($" {i + 1}. {strands[i]}");
string strand = strands[ReadInt("Strand: ", 1, strands.Length) - 1];
students[lrn] = new Student(lrn, name, grade, strand);
Console.WriteLine($"Enrolled {name} in Grade {grade} {strand}.");
}
void List(IEnumerable<Student> list)
{
var sorted = list.OrderBy(s => s.Name).ToList();
if (sorted.Count == 0) { Console.WriteLine("No students found."); return; }
Console.WriteLine($"{"LRN",-14}{"NAME",-24}{"GR",-4}STRAND");
foreach (var s in sorted)
Console.WriteLine($"{s.Lrn,-14}{s.Name,-24}{s.Grade,-4}{s.Strand}");
}
void Search()
{
string term = ReadText("Search name: ");
List(students.Values.Where(s => s.Name.Contains(term, StringComparison.OrdinalIgnoreCase)));
}
void Report()
{
Console.WriteLine($"Total enrolled: {students.Count}");
var groups = students.Values
.GroupBy(s => (s.Grade, s.Strand))
.OrderBy(g => g.Key.Grade).ThenBy(g => g.Key.Strand);
foreach (var g in groups)
Console.WriteLine($" Grade {g.Key.Grade} {g.Key.Strand,-8} {g.Count(),3} student(s)");
}
void Save()
{
File.WriteAllLines(FilePath,
students.Values.Select(s => $"{s.Lrn},{s.Name},{s.Grade},{s.Strand}"));
}
void Load()
{
if (!File.Exists(FilePath)) return;
foreach (string line in File.ReadAllLines(FilePath))
{
string[] p = line.Split(',');
if (p.Length == 4 && int.TryParse(p[2], out int grade))
students[p[0]] = new Student(p[0], p[1], grade, p[3]);
}
Console.WriteLine($"Loaded {students.Count} student(s).");
}
int ReadInt(string prompt, int min, int max)
{
while (true)
{
Console.Write(prompt);
if (int.TryParse(Console.ReadLine(), out int n) && n >= min && n <= max) return n;
Console.WriteLine($" Please enter a number from {min} to {max}.");
}
}
string ReadText(string prompt)
{
while (true)
{
Console.Write(prompt);
string text = (Console.ReadLine() ?? "").Trim().Replace(",", " ");
if (text != "") return text;
Console.WriteLine(" This can't be empty.");
}
}
record Student(string Lrn, string Name, int Grade, string Strand);
Sample run
Output
=== ENROLLMENT SYSTEM === [1] Enroll [2] List [3] Search [4] Report [0] Save & exit Choice: 1 LRN (12 digits): 136728140001 Full name: Maria Clara Santos Grade level (11-12): 11 1. STEM 2. ABM 3. HUMSS 4. GAS 5. TVL-ICT Strand: 5 Enrolled Maria Clara Santos in Grade 11 TVL-ICT. === ENROLLMENT SYSTEM === [1] Enroll [2] List [3] Search [4] Report [0] Save & exit Choice: 1 LRN (12 digits): 136728140001 That LRN is already enrolled. === ENROLLMENT SYSTEM === [1] Enroll [2] List [3] Search [4] Report [0] Save & exit Choice: 4 Total enrolled: 1 Grade 11 TVL-ICT 1 student(s)
What each part teaches
| Part | Concepts |
|---|---|
record Student | Records, properties |
Dictionary keyed by LRN | Fast lookup, no duplicates |
ReadInt, ReadText | Loops, TryParse, null handling |
List, Search, Report | LINQ: OrderBy, Where, GroupBy, tuples as keys |
Save, Load | Files and CSV |
| Menu | while (true) + switch |
ReadText replaces commas with spaces so a name can never break the CSV format.
Challenges
- Add "Drop student" by LRN.
- Limit each strand to 40 students per grade level.
- Add a section assignment: split each strand into sections of up to 40.
- Export a report file per strand.
- Turn it into a Windows Forms app with a form and a DataGridView.
What's next?
Congratulations on finishing the C# course! 🎉 From here you can try Unity for games, ASP.NET Core for websites, or connect C# to a database after our SQL course.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04