title: How to use variables declared in the Game1 class in other classes in MonoGame
body: <p>I'm trying to use a variable that is declared in <code>Game1.cs</code>, in another class.</p>
  
  <p>To simplify things, I created a new project, and want to manipulate the int variable x.
  I get <code>Object reference not set to an instance of an object.</code> at <code>game.x = 0;</code> </p>
  
  <p>I'm new to C#, anyone can tell me what the problem is, and how to fix it?</p>
  
  <p>This is the class:</p>
  
  <pre><code>class Class1
  {
      Game1 game;
  
      public void init()
      {
          game = new Game1();
      }
  
      public void Update()
      {
          game.x = 0;
          game.x++;
      }
  }
  </code></pre>
  
  <p>This is my code in <code>Game1.cs</code></p>
  
  <pre><code>public int x = 0;
  Class1 y = new Class1();
      //other stuff
  protected override void Initialize()
          {
              y.init();
              base.Initialize();
          }
  // Other stuff...
          protected override void Update(GameTime gameTime)
          {
              y.Update();
              base.Update(gameTime);
          }
  </code></pre>