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

  • Thread starter Thread starter psycho
  • Start date Start date
P

psycho

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?
 
psycho said:
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.
 
int.Parse() applies only to strings, while Convert.ToInt32() can
convert from any type.

--Freiddy
 
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
 
Back
Top