title: how to implement method that return object based on type passed
body: <p>I need to implement a method which returns an object based on type like.</p>
  
  <pre><code> public interface IBase
  { 
  }
  public class Base1 : IBase { }
  public class Base2 : IBase { }
  public class Base3 : IBase { }
  public class MyClass
  {
      public IBase GetObject&lt;T&gt;() where T:IBase
      {
          // should return the object based on type.
          return null;
      }
  
  }
  </code></pre>
  
  <p>Do i need to maintain dictionary like inside the GetObject method?</p>
  
  <pre><code>            Dictionary&lt;Type, IBase&gt; test = new Dictionary&lt;Type, IBase&gt;();
  </code></pre>
  
  <p>Is there any better way for same?</p>
  
  <p>[Edit]: - I dont want to create the object everytime. I need to keep it inside memory and when there is a call. I want to return the object from there. Apart from dictionary is there any other way?</p>