The following code throws an compile-time error like
Cannot convert type \'string\' to \'int\'
string name = Session[\"name1\"].ToString();
int i = (
There is not a default cast from string to int in .NET. You can use int.Parse() or int.TryParse() to do this. Or, as you have done, you can use Convert.ToInt32().
However, in your example, why do a ToString() and then convert it back to an int at all? You could simply store the int in Session and retrieve it as follows:
int i = Session["name1"];