【发布时间】:2015-10-16 09:32:34
【问题描述】:
如何将 Startedate 写成“?”是开始日期为空
public DateTime? StartDate { get; set; }
public override string ToString()
{
return String.Format("Course {0} ({1} is an {2} course, will be given by {3}, starts on {4}, costs {5:0.00} and will have maximum {6} participants"
, Name
, CourseId
, CourseType
, Teacher
, (StartDate == null ? "?" : StartDate)
, Price
, MaximumParticipants);
}
【问题讨论】:
-
改成
(StartDate == null ? "?" : StartDate.ToString()) -
三元语句要求两个操作数的类型相同。
标签: c# datetime string-formatting tostring