【发布时间】:2018-02-21 18:26:46
【问题描述】:
如何格式化此 var 以显示返回的日期?
var lastDropStop = shipmentStatus.Stops.LastOrDefault(x => x.StopType.ToUpper() == "DROP");
debugFile.WriteLine("lastDropStop=" + lastDropStop.ToString());
我看到的不是日期,而是类型名称:
lastDropStop=MyComp.Outbound.Business.Entities.Models.ShipmentStatusStop
【问题讨论】:
-
您只需要访问 ShipmentStatusStop 类型的日期属性吗?
debugFile.WriteLine("lastDropStop=" + lastDropStop.WhateverIsTheDateProperty.ToString());没有对象定义很难知道。 -
ToString() 的默认行为是打印出类型名称。虽然您可以覆盖它,但通常这是不必要的。只需按照其他海报所说的那样使用您想要打印的属性。
标签: c# formatting tostring