title: C# - How do I change an Object's type and then use methods from the Class?
body: <pre><code>public void ChangeObjectType(System.Type objectType, Object selectedObject)
  {
      selectedObject = Activator.CreateInstance(objectType);
  }
  
  internal void BuoyToMouse()
  {
      ChangeObjectType(typeof(Buoy), selectedObject);
      selectedObject.setPosition(mouseCurrentState.X - mouseStart.X, mouseCurrentState.Y - mouseStart.Y);
  }
  </code></pre>
  
  <p>I'm creating a game and I'm trying to handle the mouse events right now. I'm trying to use an Object of type Object and then redefine it's type depending on the type of Object that is clicked.</p>
  
  <p>When I try this I get this error message :</p>
  
  <p>Error   2   'object' does not contain a definition for 'setPosition' and no extension method 'setPosition' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)</p>
  
  <p>How do I make it understand that the <code>selectedObject</code> has changed type?</p>