Possible Duplicate:
Conditional operator assignment with Nullable<value> types?
Hi,
Why this doesn’t work?
DateTime? SomeNullableDateTime = string.IsNullOrEmpty("") ? null : Convert.ToDateTime("01/02/1982");
Is it an error somewhere? The problem seems to be the null because
DateTime? SomeNullableDateTime = string.IsNullOrEmpty("") ? Convert.ToDateTime("01/02/1982") : Convert.ToDateTime("01/02/1982");
Works fine..
Thanks
Both conditional values need to be of the same type or allow implicit conversion from one type to another, like so:
More information can be found here, but to summarize: