I have a string representing a date time, and a datetime local variable property. The string representing the datetime could be null or an empty string. To check for this, I thought I could check for a null or whitespace value and assign the appropriate value using this code: ReturnValue.ArrivalDate = string.IsNullOrWhiteSpace(Screenings.ArrivalDate) ? null : DateTime.Parse(Screenings.ArrivalDate); Pretty simple. The property `ReturnValue.ArrivalDate` is of the type `DateTime?`. So if the `Screenings.ArrivalDate` string is null or white space, it would assign the value `null` to the nullable `ReturnValue.ArrivalDate` property and if it's not null or whitespace, it would parse the string and …

Member Avatar
Member Avatar
+0 forum 1

The End.