What is faster? DirectCast(myObj, Integer) or Convert.ToInt32(myObj) ???

A

Andreas Klemt

Hello,
what has the better performance and what are you using?

Dim myObj As Object = 70
a) Dim myInt As Integer = DirectCast(myObj, Integer)
b) Dim myInt As Integer = Convert.ToInt32(myObj)

Thanks,
Andreas
 
A

Andreas Klemt

Hello John,
here are my measurements:

Convert.ToInt32 0,37
DirectCast(myObj, Integer) 0,04

Convert.ToString(myObj) 0,42
DirectCast(myObj, String) 0,07
CStr(myObj) 0,50
CType(myObj, String) 0,50

So DirectCast is much faster. What do you use?

Regards,
Andreas
 
K

Karl Seguin

Andreas, how many times do you plan on posting the same question? You've
asked it 4 times since yesterday, always slightly differently..and EACH AND
EVERY TIME someone has provided you with a quality answer.

Did you read "Conversion Functions, CType, DirectCast, and System.Convert"
at
http://msdn.microsoft.com/library/d...tml/vbtchmicrosoftvisualbasicnetinternals.asp
(as was previously provided)?? It provides a microsoft recommentation as to
which to use...what more could you possibly want?

Karl
 
A

Andreas Klemt

Hello Karl,
I was confused about DirectCast because I never heard about it.
Now after I tested it, everything is clear.

Thanks to you for the link!!

Best Regards,
Andreas
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top