using IsDate might cause performance problems?

  • Thread starter Thread starter z. f.
  • Start date Start date
Z

z. f.

Hi,

i see in reflector in inner implementation of the
Microsoft.VisualBasic.Information.IsDate function that looks like that:

public static bool IsDate(object Expression)
{
if (Expression != null)
{
if (Expression is DateTime)
{
return true;
}
if (Expression is string)
{
try
{
DateTime time1 = DateType.FromString((string)
Expression);
return true;
}
catch (Exception)
{
}
}
}
return false;
}



i understand that exceptions in general uses many resources so if i don't
want exceptions to occur in my code if not needed to i should avoid
exception if not muse happend.

so would you recomend using IsDate as a general check in my code??

TIA, z.
 
z. f. said:
i understand that exceptions in general uses many resources so if i don't
want exceptions to occur in my code if not needed to i should avoid
exception if not muse happend.

so would you recomend using IsDate as a general check in my code??

Yes. Even alternatives like 'Date.Parse'/'Date.ParseExact' will throw an
exception if the date string is in a format that is cannot be converted to a
'Date'.
 
ZF,

In my opinion is there not much better, because than in my idea would
Microsoft implemented a better solution when it had been possible. Or you
should as some people do, limit the posibilities, what is than of course not
the same as IsDate.

Don't forget that a IsDate checks all posible string versions of a date in
the current culture of the system.

Just my thought,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top