我该如何编写“?是开始日期为空写“?”在一个字符串中,如果一个属性为空
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())' – Rob
三元语句在两个操作数中都需要相同的类型。 –