Thursday, June 17, 2010

Why does this fail?

This code throws an InvalidCastException, on the grounds that you can't convert a DateTime to anything else but a string.  But I didn't think I was converting a DateTime:  I thought I was converting a nullable DateTime.
DateTime? nDate = new DateTime? (DateTime.Today);
Convert.ChangeType(nDate, typeof(DateTime?));
Tomorrow I will research this.

ETA:  The answer.

0 Comments:

Post a Comment

<< Home