You are using this overload of WriteLine
:
public static void WriteLine(object value)
and this overload call ToString
method of parameter to produce its string representation. As mentioned Here the default implementation of ToString
returns the fully qualified name of the type.
You can override ToString
in your City
class to be able use instances of this type where a string is expected like Console.WriteLine
public override string ToString()
{
return CityName + Temperature.ToString();
// return $"{CityName} : {Temperature}"; // Or use C# string interpolation
}
Or directly produce required string and pass that to WriteLine
method:
Console.WriteLine($"{item.CityName} : {item.Temperature});