title: What is the difference between Convert.ToInt32 and (int)?
body: <p>The following code throws an compile-time error like</p>
  
  <p>Cannot convert type 'string' to 'int'</p>
  
  <pre><code>string name = Session["name1"].ToString();
  int i = (int)name;
  </code></pre>
  
  <p>whereas the code below compiles and executes successfully:</p>
  
  <pre><code>string name = Session["name1"].ToString();
  int i = Convert.ToInt32(name);
  </code></pre>
  
  <p>I would like to know:</p>
  
  <ol>
  <li><p>Why does the the first code generate a compile-time error?</p></li>
  <li><p>What's the difference between the 2 code snippets?</p></li>
  </ol>