title: C# Return numeric values if the user enters characters
body: <p>I am new to C# and was playing with the loops, I just want to know how I can set the variable <strong>userTarget</strong> equal to an integer value in case if the user enters strings, i tried the TryParse method but I don't know if I really understand what I am doing with that.</p>
  
  <pre><code>static void Main()
  {
      string userChoice = string.Empty;
  
      do
      {
          Console.WriteLine("Please enter your target?");
          int userTarget = int.Parse(Console.ReadLine());
  
          int start = 0;
  
          while (start &lt;= userTarget)
          {
              Console.Write(start + " ");
              start += 2;
          }
  
          do
          {
              Console.WriteLine("Do you want to continue?");
              userChoice = Console.ReadLine().ToUpper();
  
              if (userChoice != "YES" &amp;&amp; userChoice != "NO")
              {
                  Console.WriteLine("Invalid choice, please say yes or no");
              }
  
          } while (userChoice != "YES" &amp;&amp; userChoice != "NO");
  
      } while (userChoice == "YES");
  
  }
  </code></pre>