I have this piece of code:
DateTime finalDate;
Dictionary<string, string> a = new Dictionary<string, string>() { { "a", "2016-04-14T11:56:56.0319859+02:00" } };
string dateStr;
DateTime date;
if (json.TryGetValue("a", out dateStr) && DateTime.TryParse(dateStr, out date))
{
finalDate = date;
}
But I have an error inside if: "Using the unassigned local variable myDate". If I am not mistaken if this part is fulfilled, myDate should be assigned to TryParse (technically, even if the condition was false, it should also be assigned) if I put TryParse inside if it works. Is there a way to tell the compiler that it is ok?
source
share