I'm working on a method to try to get a date from a string.
First I had this code:
public static DateTime? TryGetDate(this string date)
{
DateTime? outputDate;
if(DateTime.TryParse(date, out outputDate))
{
return outputDate;
}
return null;
}
This worked fine but then I saw a suggestion on my Visual Studio telling me to change it to:
public static DateTime? TryGetDate(this string date)
{
if(DateTime.TryParse(date, out var outputDate))
{
return outputDate;
}
return null;
}
But after that change, I got a
Syntax error, ',' expected
on the TryParse
line of code.
Why did this happen? I got a suggestion with VS but applied that suggestion and I got a compilation error? The project Target Framework version is v4.6.2