title: I cannot access a variable outside a class
body: <p>I'm making a blackjack project..</p>
  
  <p>I've firstly created the <code>Hit</code> class for the <code>Hit</code> Button.</p>
  
  <p>So on the form, when I click it, it will retrieve a value from the switch case scenario that has randomized a number/value within the hit class.</p>
  
  <p>I've tried making a variable just under the Class hit to = stRefID within the <code>GenerateID</code> method but this failed as well; everything is public, so I'm baffled.</p>
  
  <p>Thank you for your time &amp; assisting me with this, as it's my first time actually posting here, but I use this place all the time.</p>
  
  <p><strong>Hit.cs:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Blackjack
  {
  public class Hit
  {
      public static string GenerateID(int MinSize, int MaxSize)
      {
  
          string stRefID = "";
  
          Random random = new Random();
  
              int iChosenMaxSize = random.Next(0, 11);
  
              int two = 2;
              int three = 3;
              int four = 4;
              int five = 5;
              int six = 6;
              int seven = 7;
              int eight = 8;
              int nine = 9;
              int ten = 10;
              int jack = 10;
              int queen = 10;
              int king = 10;
              int ace = 11;
  
  
           for (int x = 1; x &lt;= iChosenMaxSize; x++)
          {
              int iCharType = random.Next(0, 12);
              switch (iCharType)
              {
                      case 0:
                          stRefID += two;
                          break;
                      case 1:
                          stRefID += three;
                          break;
                      case 2:
                          stRefID += four;
                          break;
                      case 3:
                          stRefID += five;
                          break;
                      case 4:
                          stRefID += six;
                          break;
                      case 5:
                          stRefID += seven;
                          break;
                      case 6:
                          stRefID += eight;
                          break;
                      case 7:
                          stRefID += nine;
                          break;
                      case 8:
                          stRefID += ten;
                          break;
                      case 9:
                          stRefID += ace;
                          break;
                      case 10:
                          stRefID += jack;
                          break;
                      case 11:
                          stRefID += queen;
                          break;
                      case 12:
                          stRefID += king;
                          break;
  
                  }
               } return stRefID; 
  
          }
      }
  }
  </code></pre>
  
  <p>And where I would like to retrieve and set the text box to the value retrieved:</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace Blackjack
  {
  public partial class Form1 : Form
  {
  
  
          private void hit_Click(object sender, EventArgs e)
      {
  
           this.test.Text = Hit.stRefID;
  
      }
  </code></pre>
  
  <p>I've attempted making the button public as well but this failed...</p>
  
  <p>test text box for output:</p>
  
  <pre><code>private void test_TextChanged(object sender, EventArgs e)
      {
  
      }
  </code></pre>
  
  <p>Kind regards,
  Mike.</p>
  
  <p>Revised Code:</p>
  
  <pre><code>namespace Blackjack
  {
  public class Hit
  {
  
      public static string GenerateID(string stRefID)
  
      {
  
          Random random = new Random();
  
              int iChosenMaxSize = random.Next(0, 11);
  
              int two = 2;
              int three = 3;
              int four = 4;
              int five = 5;
              int six = 6;
              int seven = 7;
              int eight = 8;
              int nine = 9;
              int ten = 10;
              int jack = 10;
              int queen = 10;
              int king = 10;
              int ace = 11;
  
  
           for (int x = 1; x &lt;= iChosenMaxSize; x++)
          {
              int iCharType = random.Next(0, 12);
              switch (iCharType)
              {
                      case 0:
                          stRefID += two;
                          break;
                      case 1:
                          stRefID += three;
                          break;
                      case 2:
                          stRefID += four;
                          break;
                      case 3:
                          stRefID += five;
                          break;
                      case 4:
                          stRefID += six;
                          break;
                      case 5:
                          stRefID += seven;
                          break;
                      case 6:
                          stRefID += eight;
                          break;
                      case 7:
                          stRefID += nine;
                          break;
                      case 8:
                          stRefID += ten;
                          break;
                      case 9:
                          stRefID += ace;
                          break;
                      case 10:
                          stRefID += jack;
                          break;
                      case 11:
                          stRefID += queen;
                          break;
                      case 12:
                          stRefID += king;
                          break;
  
                  }
            } return stRefID; 
  
          }
  
  }
  }
  </code></pre>
  
  <p>I made the generateID method with stRefID because the return should go back to it - whereby I can call the value from the button? the public static string declaration works but only if I have a defaul value...</p>