Returning different object types via Generics

I wanted to use generics to create a Load method that would return different results based on the Generic Type. This is how I did it;

     
public T Load(string logicalChoice, params object[] arguments)         
{                              
  T o = (T)Activator.CreateInstance(typeof(T)); 		
  if (logicalChoice=="choice1") 		
  {                		
    MyList list = o as MyList;                 	
    list.Add(new Item { Id = 100, Description = "Fruit" });                 	
    list.Add(new Item { Id = 110, Description = "Dairy" });                 
  } 		
  else 		
  { 			
    Item item = o as Item;                 	
    item.Id = 100; 			
    item.Description = "Fruit";  		
  }                 
  return o;                     
}     

Leave a comment