title: Unable to pass a parameter in C#?
body: <p>Okay. For the iLab my class and I are doing this week, we are working with GUIs. The second program we must design is a guessing game. The program is supposed to randomly generate a number, 0 through 100, and pass that number on to be used later. Here is the code I already have.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace Guessing_game
  {
      public partial class Form1 : Form
  
      {
          int target();
          public Form1()
          {
              InitializeComponent();
              Random r = new Random();
              int target = r.Next(0, 100);
          }
  
          private void btnEvaluate_Click(object sender, EventArgs e)
          {
              if (txtGuess.Text == target)
              {
  
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Mind you, the "btnEvaluate_Click" area is not done. This is because the variable "Target" that should be accessible by the program is unable to be read later on. </p>
  
  <p>After reading through some of the comments, I was able to tweak the code so I get one more error: "Field 'Guessing_game.Form1.target' is never assigned to, and will always have its default value 0" IF anyone is going to try and replicate this, I can tell you exactly how to write it. The GUI should have a label, a text box, and a button. The button needs to get the value given to "target" so it can check the user's guess against target's value. I'm using Visual Studio 2010, if it helps.</p>