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

  • Thread starter Thread starter Andreas Klemt
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top