title: Generic Type Conversions
body: <p>I am trying to convert an object to a generic type.  Here is an example method:</p>
  
  <pre><code>void Main()
  {
      object something = 4;
      Console.WriteLine(SomeMethod&lt;int&gt;(something));
      Console.WriteLine(SomeMethod&lt;string&gt;(something));
  }
  
  public T SomeMethod&lt;T&gt;(object someRandomThing)
  {
  
      T result = Convert.ChangeType(someRandomThing, typeof(T));
  
      return result;
  }
  </code></pre>
  
  <p>This gives this error:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'object' to 'T'. An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>I have tried several variations to get my result cast as the generic type, but it is not working out each time.</p>
  
  <p><strong>Is there a way to make this cast?</strong></p>
  
  <p>NOTE: In my real example I am getting an "object" back from a stored procedure.  The method could call one of several stored procedures, so the result could be a string or a int (or long) depending on which sproc is called.</p>