CType(x,Integer) vs. Integer.Parse(x)

CType(x,Integer) vs. Integer.Parse(x)

Post by Sm9l » Tue, 07 Feb 2006 22:23:27


Hello All:

Does anyone know the difference between CType(x,Integer) vs.
Integer.Parse(x)? Is there a performance advantage to one or the other?

TIA,
--
Joe
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by m.posset » Tue, 07 Feb 2006 23:04:44


CType:

Returns the result of explicitly converting an expression to a specified
data type, object, structure, class, or interface.

Parse :

Parses the string parameter and converts it to an integer value.


CType is compiled inline, which means that the conversion code is part of
the code that evaluates the expression. In some cases there is no call to a
procedure to accomplish the conversion, which makes execution faster


regards

Michel Posseth [MCP]

 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by m.posset » Tue, 07 Feb 2006 23:04:51


CType:

Returns the result of explicitly converting an expression to a specified
data type, object, structure, class, or interface.

Parse :

Parses the string parameter and converts it to an integer value.


CType is compiled inline, which means that the conversion code is part of
the code that evaluates the expression. In some cases there is no call to a
procedure to accomplish the conversion, which makes execution faster


regards

Michel Posseth [MCP]
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by Sm9l » Tue, 07 Feb 2006 23:15:29

Michel,

It sounds like CType is really the way to go.

Thanks.
--
Joe
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by Sm9l » Tue, 07 Feb 2006 23:18:31

Michel,

One more question:

Can you think of an ocassion when one would want to use Integer.Parse(x) or
Double.Parse(x) in lieu of CType(x,Integer) or CType(x,Double)?
--
Joe
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by Karl Segui » Tue, 07 Feb 2006 23:33:22

Portability to other .NET languages.

Karl
--
MY ASP.Net tutorials
http://www.yqcomputer.com/
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by Sm9l » Wed, 08 Feb 2006 00:30:28

Thanks.
--
Joe
 
 
 

CType(x,Integer) vs. Integer.Parse(x)

Post by RGF2aWQgQW » Wed, 08 Feb 2006 11:30:27

If you're comparing VB conversion 'macros' (they aren't methods) and .NET
methods, then the correct .NET comparison is the System.Convert methods, not
the various "Parse" methods or C# casts.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter