Class List Keeps Printing Out As Class Name In Console?

前端 未结 4 755
北荒
北荒 2020-11-27 09:02

Ok, so maybe I\'m just tired or something but I can\'t seem to figure out why this keeps happening.

The code below is called every day for a data point in a database

4条回答
  •  囚心锁ツ
    2020-11-27 09:12

    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.

提交回复
热议问题