473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Casting Performance

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

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

Jun 9 '06 #1
5 2286
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

"Charlie Brown" <cb****@duclaw.com> schreef in bericht
news:11**********************@y43g2000cwc.googlegr oups.com...
Which is best to use in terms of performance/proper usage.

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

Jun 9 '06 #2
Wouldn't there be some loss in CDate(obj as Expression) since it
doesn't know the object type beforehand?
Cor Ligthert [MVP] wrote:
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

"Charlie Brown" <cb****@duclaw.com> schreef in bericht
news:11**********************@y43g2000cwc.googlegr oups.com...
Which is best to use in terms of performance/proper usage.

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


Jun 9 '06 #3
> 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


Cor Ligthert [MVP] wrote:
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

"Charlie Brown" <cb****@duclaw.com> schreef in bericht
news:11**********************@y43g2000cwc.googlegr oups.com...
> Which is best to use in terms of performance/proper usage.
>
> Convert.ToDateTime(strDate)
> CType(strDate, DateTime)
> CDate(strDate)
>

Jun 9 '06 #4
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
"Charlie Brown" wrote:
Which is best to use in terms of performance/proper usage.

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

Jun 9 '06 #5
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
Jun 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Reece Hart | last post by:
Here's the basic issue: PostgreSQL doesn't use indexes unless a query criterion is of exactly the same type as the index type. This occurs even when a cast would enable the use of an index and...
18
by: Marco | last post by:
I need to get a iterator from any generic collection. public class .... GetIterator(Object collection) { ..... }
1
by: Remco | last post by:
Hi, Let me try to simply explain my questions. I've created a portal site with different types of users, e.g. Portal Administrators and Normal Users. One base class SessionUser (has a enum...
61
by: Ken Allen | last post by:
I am relatively new to .Net, but have been using VB and C/C++ for years. One of the drawbacks with VB6 and earlier was the difficulty in casting a 'record' to a different 'shape' so one could...
23
by: PeterOut | last post by:
If I had code like this. unsigned short usLimit=10 int a, i; for (i=0; i<(int)usLimit; ++i) { a=(int)usLimit; }
6
by: Ken Fine | last post by:
This is a basic question. What is the difference between casting and using the Convert.ToXXX methods, from the standpoint of the compiler, in terms of performance, and in other ways? e.g. ...
5
by: johanatan | last post by:
Does anyone know the reasons for the lack of an implicit casting operator in any greater depth than: A. Automatic conversion is believed to be too error prone. (from the FAQ at the bottom of:...
29
by: Tony Johansson | last post by:
Hello! Here I have two different way to use casting. Is any of these any better then the other? Or is it just a question of taste. newCards.Add((Card)sourceCard.Clone());...
19
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.