How can I write
string date = "12/2/2011";
DateTime? dt = date ?? DateTime.Parse(date);
this throws a compile time error. I know I can do tryparse or do if {}. Is there any way to do this in one line?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try using the conditional operator
?:instead of the null-coalescing operator??:You also need to cast the null to
DateTime?otherwise you will get a compile error.