title: How to cast an int into a nullable type?
body: <p>I'm just doing simple int swap program. I also just learnt about casting so I'm trying it out in this program. But I'm getting an error that says I should do an explicit cast. </p>
  
  <p>I don't think I understand the concept of casts. What's the problem?</p>
  
  <pre><code>static void Main(string[] args)
  {
      Console.WriteLine("Enter the FIRST Integer.");
      string tempint1 = Console.ReadLine();
      int int1 = Convert.ToInt32(tempint1);
  
      Console.WriteLine("Enter the SECOND Integer.");
      string tempint2 = Console.ReadLine();
      int int2 = Convert.ToInt32(tempint2);
  
      Console.WriteLine();
  
      int? swapInt = null;
      swapInt = (int)int1;
      int1 = int2;
      int2 = swapInt;
  
      Console.WriteLine("The integers have been swapped!");
      Console.WriteLine("The FIRST INTEGER is now " + int1);
      Console.WriteLine("The SECOND INTEGER is now " + int2);
      Console.WriteLine();
  }
  </code></pre>