Why doesn't the conditional operator correctly allow the use of "null" for assignment to nullable ty

Posted by Daniel Coffman on Stack Overflow See other posts from Stack Overflow or by Daniel Coffman
Published on 2010-03-15T22:18:57Z Indexed on 2010/03/15 22:19 UTC
Read the original article Hit count: 387

Filed under:
|
|
|
  1. This will not compile, stating "Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DateTime' and ''"

    task.ActualEndDate = TextBoxActualEndDate.Text != "" ? DateTime.Parse(TextBoxActualEndDate.Text) : null;

  2. This works just fine

    if (TextBoxActualEndDate.Text != "") task.ActualEndDate = DateTime.Parse(TextBoxActualEndDate.Text); else task.ActualEndDate = null;

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET