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

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
int.Parse() applies only to strings, while Convert.ToInt32() can
convert from any type.

--Freiddy

Feb 3 '07 #3

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.