将var = ... firstOrDefault显示为字符串而不是typename

时间:2018-02-21 18:26:46

标签: c# formatting tostring

如何格式化此var以显示返回的日期?

var lastDropStop = shipmentStatus.Stops.LastOrDefault(x => x.StopType.ToUpper() == "DROP");
debugFile.WriteLine("lastDropStop=" + lastDropStop.ToString());

我没有看日期,而是看到了类型名称:

lastDropStop=MyComp.Outbound.Business.Entities.Models.ShipmentStatusStop

1 个答案:

答案 0 :(得分:1)

您正在打印该对象,您应该像这样编写属性名称

debugFile.WriteLine("lastDropStop=" + lastDropStop.StopType.ToString()); // or lastDropStop.LastDropStop.ToString() or whatever the property name is