Windows Phone Controls - DatePicker - Nullable Data Type?

I'm currently developing a new application for windows phone and added a windows phone toolkit - DataPicker. On trying to read the date value to a DateTime variable I found the "Value" was of type "DateTime?" which the compiler wasn't happy about.

After some searching I found that the "?" after the variable type stands for "Nullable Data Type" which I hadn't seen before. The "DateTime?" type has a method "GetValueOrDefault( DateTime DefaultValue )" which allows a default time value to be returned if the Value would have been Null.

So I used the following syntax for the control:

localDateTime1 = datePicker1.Value.GetValueOrDefault( newDateTime(1900,1,1,0,0,0,DateTimeKind.Utc))

Thanks to Richard Carr for his usefull information on NullableDataTypes:




Posted in Windows Phone | Leave a comment