我該如何編寫「?是開始日期爲空寫「?」在一個字符串中,如果一個屬性爲空
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
三元語句在兩個操作數中都需要相同的類型。 –