473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

what is the difference wetween Int32.parse and Convert.ToInt32

what is the difference between the two forms of converting to integer
from string

string strVal = "10";

Convert.ToInt32(strVal);

Int32.Parse(strVal);

which method is more efficient in terms of performance?

Feb 3 '07 #1
3 2158
psycho <pa***********@gmail.comwrote:
what is the difference between the two forms of converting to integer
from string

string strVal = "10";

Convert.ToInt32(strVal);

Int32.Parse(strVal);
Convert.ToInt32 returns 0 if you pass it null. Int32.Parse will throw
an exception.
which method is more efficient in terms of performance?
The difference is trivial. You should pick based on the semantics you
want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 3 '07 #2
int.Parse() applies only to strings, while Convert.ToInt32() can
convert from any type.

--Freiddy

Feb 3 '07 #3
On Feb 3, 11:13 pm, "Freiddy" <fei.yua...@gmail.comwrote:
int.Parse() applies only to strings, while Convert.ToInt32() can
convert from any type.

--Freiddy
Well, Conver.ToInt32 calls int.Parse at the end. It totally depends
what you want to use and ofcourse Convert will give you more options.

Cheers,
amer

Feb 3 '07 #4

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

Similar topics

10
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
4
by: Daniel Walzenbach | last post by:
Hi, I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same...
16
by: Jim in Arizona | last post by:
I'm familiar with CInt(value) but I'm not with Int32.Parse(value). They seem to do the same thing. Is there a big difference between the two and when would one be best applied over the other? ...
1
by: Paul Aspinall | last post by:
Hi Can anyone offer a comparison of System.Convert.ToInt32 vs Int32.Parse Thanks
4
by: Rich | last post by:
Hello txtID.Text contains a 6 digit Integer number with no decimals, no chars... Dim j As Integer = Cint(txtID.Text) or Dim j As Integer = Convert.ToInt32(txtID.Text)
14
by: =?Utf-8?B?R3JlZ2cgV2Fsa2Vy?= | last post by:
Hopefully someone can set me straight on this issue. I was testing some code where I have a method that is being overriden. The method overrides were working fine until I passed a literal 0 (int...
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. ...
14
by: Just_a_fan | last post by:
In VB6, I could easily take the value from a combo box and make a command with it, this: baudrate = cboBaud(listindex). With the new dotted stuff in VB9, I can't seem to do that. Here's an...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.