Jean101
Member
- Joined
- Feb 8, 2020
- Messages
- 10
- Programming Experience
- 1-3
_school = new Dictionary<string, List<Student>>();
//...
_school.Add(myStudent.name, new List<Student>());
if (_school == null)
{
_school = new Dictionary<string, List<Student>>();
}
private Dictionary<string, List<Student>> _school = new Dictionary<string, List<Student>>();
_school.Add(myStudent.name, new List<Student>());
Perhaps I'm missing something, by why are you adding the student name as a key with an empty student list on line where you have:
C#:_school.Add(myStudent.name, new List<Student>());
private void AddStudent()
{
Console.Clear();
//Setting UI color
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Add Student: ");
Console.WriteLine("============");
Console.WriteLine("============");
Console.ForegroundColor = ConsoleColor.Gray;
//Instantiation
_school = new Dictionary<string, List<Student>>();
Student myStudent = new Student("Jean", "Web");
myStudent.name = Validation.ValidateString("\nPlease enter student name: ");
_school.Add(myStudent.name, new List<Student>());
myStudent.degree = Validation.ValidateString("Please enter student degree: ");
_school.Add(myStudent.degree, new List<Student>());
_school[myStudent.name].Add(myStudent);
Console.WriteLine($"New student created {myStudent.name} {myStudent.degree}");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
_myMenu.Display();
Selection();
}
thank you very much. Will do.I have explained why you had the issue of only one student being in your dictionary. That doesn't mean that there aren't other issues with the code. They are not related to the issue you asked about though. If you have other issues, you really ought to create new threads for them: one topic per thread and one thread per topic. How to properly store the data for students and degrees is a different topic. You should also provide a title that is more descriptive of the actual issue.