Casting Performance

  • Thread starter Thread starter Charlie Brown
  • Start date Start date
C

Charlie Brown

Which is best to use in terms of performance/proper usage.

Convert.ToDateTime(strDate)
CType(strDate, DateTime)
CDate(strDate)
 
Charlie,

You forgot the datetime.parse, but advices in VBNet is the CDate as that is
possible, not only because it is the shortest but has as well some extra's
in it.

As you need thousands of nanoseconds than you can use as well the
datetime.parse

I hope this helps,

Cor
 
Wouldn't there be some loss in CDate(obj as Expression) since it
doesn't know the object type beforehand?
 
Wouldn't there be some loss in CDate(obj as Expression) since it
doesn't know the object type beforehand?
I wrote that, but not comparing to CType which means not Cast but Convert
Type, casting is in VBNet DirectCast but that you cannot use here.

As I wrote, if you needs thousands of nanoseconds use DateTime.parse but
that is not as adviced in VBNet that is CDate.

Old VB6 developers are a little bit scary from CDate, however AFAIK is the
CDate renewed in VBNet.

But if thousands of nanoseconds are important for your application than

http://msdn2.microsoft.com/en-us/library/1k1skd40.aspx

Don't forget that all VBnet conversion methods are more forgiving full than
the system.net methods.

Cor
 
CDate is a shorthand syntax for CType(..., Date).
In general the VB macros C<type> are identical to the corresponding CType.

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter
 
David,
In general the VB macros C<type> are identical to the corresponding CType.
That should be an exception, there is written in the performance paragraph
that there is added something to the Cxxx conversion methods in general. For
some is told that it even *after* the CLI has some boosting in it.

Cor
 
Back
Top