See the answer from the similar question "Dynamically Create a Generic Type for Template". The only difference is that they are generating the type from the command line, the rest you should be able to adapt to your needs.
As an aside, you cannot call typeof on an instance - to get the type of an instance (for example "i" call GetType():
Type intType = i.GetType();