For example conversion from string to integer
string s="123";
int i = Convert.toInt32(s.ToString()); // no error
but if s="abc";
and int i = Convert.ToInt32(s.ToString()); // run time error
so its always better to check before conversion as
int res;
bool NoError = Int32.TryParse(s.ToString(), out res)
if(!NoError ){ Console.WriteLine("Conversion is not possible"); }
else{ i = Convert.ToInt32(s.ToString());}
Thursday, January 7, 2010
Subscribe to:
Posts (Atom)