Saturday, March 13, 2010 3:37 PM
For some unknown reason you can’t do a TryParse on nullable types or should I say the out parameter of a TryParse can not be nullable? For example this just won’t work.
DateTime? dt;
DateTime.TryParse("12/12/2010", out dt);
Error 4 The best overloaded method match for 'System.DateTime.TryParse(string, out System.DateTime)' has some invalid arguments
The solution or workaround is to use two variables to accomplish the goal, here is an example.
DateTime? dt1;
DateTime dt2;
dt1 = DateTime.TryParse("12/12/2010", out dt2) ? dt2 : (DateTime?)null;