no implicit conversion between null to int

I faced this issue twice now.

When I tried to use below code
DateTime? foo;
foo = string.IsNullOrEmpty(txtDate.Text) ? null : Convert.ToDateTime(txtDate.Text);
I get error as,
Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'System.DateTime'

Solution for the problem is below
DateTime? foo;
foo = string.IsNullOrEmpty(txtDate.Text) ? (DateTime?)null : Convert.ToDateTime(txtDate.Text);



Reference: Muthukumar (http://nadarmuthukumar.blogspot.in)

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More