Microsoft.SharePoint.WebControls.DateTimeControl.IsDateEmpty and Nullable issue

The other day I used the IsDateEmpty property of a DateTimeControl and I wanted to assign the appropriate value to a Nullable DateTime variable like in this example:

DateTime? ReplyLimit = ReplyLimitDateTimeControl.IsDateEmpty ? null : ReplyLimitDateTimeControl.SelectedDate;

Type of conditional expression cannot be determined because there is no implicit conversion between ‘System.DateTime’ and ‘<null>’

 

Unfortunately that didn’t compile with the above error message and I fixed by casting the null value to a Nullable DateTime of null, like this: 

DateTime? ReplyLimit = ReplyLimitDateTimeControl.IsDateEmpty ? (DateTime?)null : ReplyLimitDateTimeControl.SelectedDate;

,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: