// If anyone can help me I'd appreciate it.
// More than happy to buy you a coffee. Just give me your email address.
// Not looking for any free information.
// used this to create the student object with no issues.
public Student(string first, string last)
{
FirstName = first;
LastName = last;
}
// i've had no issues storing the object in this dictionary.
// used to add student to dictionary.
Student.current.Add(Student.student_ID, added);
// actual dictionary.
public static Dictionary current = new Dictionary();
// Previously had Students being stored in list with no issues when grabbing values.
// Now I want to print each student stored in the dictionary with all values //pertaining to each student.
public static void printStudents()
{
foreach (KeyValuePair pair in current)
{
Console.WriteLine("{0}, {1}", pair.Key, Student.FirstName);
Console.WriteLine("{0}, {1}", pair.Key, Student.LastName);
}
}
// this is my old code had no issues.
/*
foreach (var listing in current)
{
Console.WriteLine("\nStudent ID: {0}", listing.ID);
Console.WriteLine("First Name: {0}", listing.FirstName);
Console.WriteLine("Last Name: {0}\n", listing.LastName);
}
*/
What I have tried:
I feel like I've tried everything.
Maybe in dictionaries, data can't be extracted directly ?
解决方案Console.WriteLine("{0}, {1}", pair.Key, pair.Value.FirstName);
Console.WriteLine("{0}, {1}", pair.Key, pair.Value.LastName);