The following code throws an compile-time error like
Cannot convert type \'string\' to \'int\'
string name = Session[\"name1\"].ToString(); int i = (
A string cannot be cast to an int through explicit casting. It must be converted using int.Parse.
int.Parse
Convert.ToInt32 basically wraps this method:
public static int ToInt32(string value) { if (value == null) { return 0; } return int.Parse(value, CultureInfo.CurrentCulture); }