Class List Keeps Printing Out As Class Name In Console?

前端 未结 4 743
北荒
北荒 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:14

    this will work without having to use .ToString()

    public class SharePrices
    {
        public DateTime theDate { get; set; }
        public decimal sharePrice { get; set; }
    }
    
    SharePrices sp = new SharePrices() { theDate = DateTime.Now, sharePrice = 10 };
    
    var newList2 = new List();
    newList2.Add(sp);
    newList2.ForEach(itemX => Console.WriteLine("Date: {0} Sharprice: {1}",sp.theDate, sp.sharePrice));
    

提交回复
热议问题