title: C# - How do I see what subclass a certain instance is when looking through a list of base instances?
body: <p>I am developing a game as a school project using XNA. I'm trying to create a code in my "Entity" base class that checks what specific subclass of "Entity" that i'm currently colliding with.</p>
  
  <p>This is what I've been trying to use so far: </p>
  
  <p><em>in "Entity"</em></p>
  
  <pre><code> protected Entity CheckCollisionWithEntity(Vector2 pos)
      {
          Rectangle r = new Rectangle((int)pos.X, (int)pos.Y, _texture.Width, _texture.Height - 1);
  
          foreach (Entity e in _entities)
          {
              if (r.Intersects(e.Collider))
              {
                  if(e != this)
                  return e;
              }
  
          }
  
          return null;
      }
  </code></pre>
  
  <p><em>in "Player" (which is, like "Enemy", a subclass of "Entity")</em></p>
  
  <pre><code>  if (CheckCollisionWithEntity(Position) is Enemy)
          {
              Game1.instance.reloadLevel();
          }
  </code></pre>
  
  <p>My problem is that when I collide with an "Enemy" instance - nothing happens.
  I know for a fact that the "reloadLevel()" method works, and I have tried switching it out for debug code. 
  What am I doing wrong here? Have I misunderstood the "is" reference?
  The enemies Colliders are working for other less specific types of colission checking.</p>