Reputation: 749
In our existing website code I encountered the following piece of code:
private static bool IsDate(string inputText)
{
try
{
DateTime.Parse(inputText);
return true;
}
catch
{
return false;
}
}
Can this piece of code be optimized by using .NET 4.0 framework feature?
Upvotes: 0
Views: 1759
Reputation: 570
bool IsDate(string Input)
{
DateTime RV;
return DateTime.TryParse(Input, out RV);
}
Upvotes: 0
Reputation: 245499
No. But it could be optimized using other Framework features that have been around for a lot longer than 4.0:
private static bool IsDate(string inputText)
{
DateTime d;
return DateTime.TryParse(inputText, out d);
}
Upvotes: 5