By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

which is faster convert or directcast

P: n/a
Which is faster or considered the better way to do this.

I have a object that holds a date...

Convert.ToDate(object)

or Directcast(object,DateTime)

? Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Brian,

Because it are less characters to type

CDate(Object)

One of the extras of VBNet is that it has a lot of powerfull conversion
methods.

Cor
Nov 21 '05 #2

P: n/a
DirectCast is faster, but it assumes you know the Type at runtime though.
For example,

MyEventHandler( Sender as Object , e as EventArgs )
// 'Sender' Cannot be evaluated as a type until runtime, so this assumes
this is the correct type.
Regards

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ui*************@TK2MSFTNGP10.phx.gbl...
Which is faster or considered the better way to do this.

I have a object that holds a date...

Convert.ToDate(object)

or Directcast(object,DateTime)

? Thanks

Nov 21 '05 #3

P: n/a
Hi Terry,

Where did you been, I thought he has taken hollidays.

I even answered an hour ago a question about "proper case" which I always
leave for you.

One of the message from you I saw in this newsgroup where you had a
(friendly) discussion about that with Herfried. Was something about Correct
case I thought.

:-)

Cor
Nov 21 '05 #4

P: n/a
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
Which is faster or considered the better way to do this.

I have a object that holds a date...

Convert.ToDate(object)

or Directcast(object,DateTime)


Start "ILDASM" and take a look at the IL that is generated for both of
the methods. The implementation if 'ToDate' can be found here:

<URL:http://sharedsourcecli.sscli.net/source/browse/sharedsourcecli/clr/src/bcl/system/convert.cs?rev=1.1.1.1&content-type=text/vnd.viewcvs-markup>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
Sorry, it was just another method !
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hi Terry,

Where did you been, I thought he has taken hollidays.

I even answered an hour ago a question about "proper case" which I always
leave for you.

One of the message from you I saw in this newsgroup where you had a
(friendly) discussion about that with Herfried. Was something about Correct case I thought.

:-)

Cor

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.