title: How to refer to an object outside the main method in the same class?
body: <p>In the process of creating a game using C# and the graphics library SFML, I encountered the error "The name 'fighter' does not exist in the current context". I am unsure of how to refer to the object in the SFML static event method MouseButtonPressed(), as it returns the above error.</p>
  
  <p>I am aware that you could declare the object as static, as I have done (and commented out below) in the code. However, throughout the game, an unknown number objects will be created, and so I don't think you make multiple instance fields.
  What is the best approach?</p>
  
  <p>Relevant code:</p>
  
  <pre><code>namespace Game
  {
      public class Program
      {
          //I don't want to have to do this
          //static Unit fighter;
  
          Texture textureFighter;
          static void MouseButtonPressed(object sender, MouseButtonEventArgs e)
          {
              if (e.Button == Mouse.Button.Left)
              {
                  fighter.Move(new Vector2f(Mouse.GetPosition().X, Mouse.GetPosition().Y));
              }          
          }
          public static void Main()
          {
             Program myProgram = new Program();
  
             myProgram.textureFighter = new Texture(@"resources\ship_fighter.png");
  
             Unit fighter = new Unit(new Vector2f(100, 100), 0)
              {
                  Texture = myProgram.textureFighter
              };
              ...
          }
  
      }
  }
  </code></pre>