Possible Duplicate:
difference between Convert.ToInt32 and (int)
What it difference between (int)
and convert.toint()
methods?
like
object o = 123;
int i = (int)o;
and
int i = Convert.ToInt16(o);
What is the difference in both of them?
Possible Duplicate:
difference between Convert.ToInt32 and (int)
What it difference between (int)
and convert.toint()
methods?
like
object o = 123;
int i = (int)o;
and
int i = Convert.ToInt16(o);
What is the difference in both of them?
You can convert another type to an int but to cast to an int it needs to be a boxed int.
e.g.:
string s = "123";
int i = Convert.ToInt16(s);
or
object o = 123;
int i = (int)o;
works fine. However:
string s = "123";
int i = (int)s;
won't compile.