title: Accessing a function of a class from a function of another class
body: <p>I am trying to access the Update function of Key from the Update function of MainChar. Both classes inherit from the Sprite class. In Main Char I am getting the error:</p>
  
  <p>An object reference is required for the non-static field, method, or property 'Key.Update(GameTime, List)'. I have tried putting the type before the parameters but I get the errors:</p>
  
  <p>'GameTime' is a type, which is not valid in the given context, 
  'Sprite' is a type, which is not valid in the given context. </p>
  
  <p>I have also tried creating a new instance of Key by doing:
  Key key = new Key(texture, position);
  I again tried putting the types before but just got:
  Key does not contain a constructor that takes 4 arguments, and they aren't valid in the given context. Help would be apprieciated. </p>
  
  <p>This question was associated with a similar question which did not solve my question because I can't make Update or Key static.</p>
  
  <pre><code>  public MainChar(Texture2D texture) : base(texture)
      {
          Scale = 0.1f;
      }
  
      public override void Update(GameTime gameTime, List&lt;Sprite&gt; sprites)
      {
          Move();
  
          foreach (var sprite in sprites)
          {
              if (sprite == this)
              {
                  continue;
              }
  
              if (Velocity.X &gt; 0 &amp;&amp; IsTouchingLeft(sprite) || Velocity.X &lt; 0 &amp;&amp; IsTouchingRight(sprite)) 
              {
                  Velocity.X = 0;
              }
  
              if (Velocity.Y &gt; 0 &amp;&amp; IsTouchingTop(sprite) || Velocity.Y &lt; 0 &amp;&amp; IsTouchingBottom(sprite))
              {
                  Velocity.Y = 0;
              }
  
              if (sprite.rectangle.Intersects(rectangle))
              {
                  hasDied = true;
  
              }
  
              if (sprite is Key)
              {
                  Key.Update(gameTime, sprites);
              }
          }
  
          Position += Velocity;
       }
  </code></pre>
  
  <pre><code>     public int keyCount;
  
          public Key(Texture2D texture, Vector2 position) : base(texture)
          {
              Position = position;
              Scale = 0.08f;
          }
  
          public override void Update(GameTime gameTime, List&lt;Sprite&gt; sprites)
          {
              foreach (var sprite in sprites)
              {
  
                  if (sprite is MainChar)
                  {
  
                      if (IsTouchingLeft(sprite)  == true || IsTouchingRight(sprite) == true || IsTouchingTop(sprite) == true || IsTouchingBottom(sprite) == true)
                      {
                          Position = new Vector2(1000, 1000);
                          keyCount++;
                      }
                  }
              }
          }
  
  </code></pre>