Class List Keeps Printing Out As Class Name In Console?

C# doesn't know anything about the SharePrices other than the class name. If you want it to display something specific, you will need to override the ToString() method like so:

public override string ToString()
{
    return "SharePrice: " + theDate.ToString() + ": " + sharePrice.ToString();
}

Of course, you can format it however you like, that is the beauty of it. If you only care about the price and not the date, only return the sharePrice.


You should override ToString() for your class in format as you want, for example like this:

public class SharePrices
{
    public DateTime theDate { get; set; }
    public decimal sharePrice { get; set; }

    public override string ToString()
    {
        return String.Format("The Date: {0}; Share Price: {1};", theDate, sharePrice);
    }
}

By default, without overriding, ToString() returns a string that represents the current object. So that's why you get what you described.


When you call Console.WriteLine on a class, it will call the ToString() method on that class automatically.

If you want to print the details out, you will over need to override ToString() in your class, or call Console.WriteLine with each property you want to print out.