title: Is there a way to return a value from a try-catch block into a preexisting variable outside of the block itself?
body: <p>I feel like this may be somewhat of a dumb question, but I've tried everything I currently know to do as a beginner of C# on this. Is there any way I can return a value into one I've already set to use elsewhere? Or am I just over-complicating this whole thing? Every time I try to set the already existing variable with one inside the curly brackets I get an error. Code I used below.</p>
  <pre class="lang-cs prettyprint-override"><code>static double GetAmount()
  {
      double amount;
      try
      {
          Console.WriteLine(&quot;Enter in the amount for the transaction: &quot;);
          double amount1 = Convert.ToDouble(Console.ReadLine());
          return amount1;
      }
      catch (Exception ex)
      {
          bool f = true;
          Console.WriteLine(ex.Message);
          while (f == true)
              try
              {
                  Console.WriteLine(&quot;Enter the total in a proper format, no letters or spaces please. &quot;);
                  double amount1 = Convert.ToDouble(Console.ReadLine());
                  f = false;
                  return amount1;
              }
              catch (Exception ex2)
              {
                  Console.WriteLine(ex2.Message);
                  Console.WriteLine(&quot;Please try again.&quot;);
              }
      }
      finally
      {
          return amount;
      }
      return amount;
  }
  </code></pre>