difference between Convert.ToInt32 and (int)
Posted
by balalakshmi
on Stack Overflow
See other posts from Stack Overflow
or by balalakshmi
Published on 2009-10-22T17:40:45Z
Indexed on
2010/03/08
2:12 UTC
Read the original article
Hit count: 332
c#
|type-conversion
the following syntax throws an compile time error like
Cannot convert type 'string' to 'int'
string name=(Session["name1"].ToString());
int i = (int)name;
whereas the code below compiles and executes successfully
string name=(Session["name1"].ToString());
int i = Convert.ToInt32(name);
I would like to know
1) why the compile time error occurs in first code
2) what's the difference between the 2 code snippets
© Stack Overflow or respective owner