That's because your
StudentData
class doesn't implement
ToString
- so the default version for
object
is used instead, and that prints the full name of the class (because it doesn't "know" about the content you added and what you want printed).
Try this:
public class StudentData
{
public string firstName;
public string lastName;
public int age;
public override string ToString()
{
return $"{firstName} {lastName} is {age} years old";
}
}
Or better, this:
public class StudentData
{
public string firstName { get; set; }
public string lastName { get; set; }
public int age { get; set; }
public override string ToString()
{
return $"{firstName} {lastName} is {age} years old";
}
}
Because you shouldn't expose fields directly - use properties instead.