I know this might be a silly question but here goes. I intend to create a list using C# code. I do know the code but the question is, where exactly should I write the code in Visual studio. I mean which template to use (webpart, visual webpart) and do I need to add some references.
Check this post http://msdn.microsoft.com/en-us/library/gg276355.aspx . it will give you some ideas.
To answer your question, You can write the code wherever you want and it depends on the scenario. I can use a Visual WebPart to create a new list.
I can also develop a event handler/feature to create a list programatically. Above link uses List Definitions.
Shoban said the critical phrase in his answer.
It really does depend on your situation. Normally I have lists created upon site creation, so I'll do this via CAML code and have it as part of a feature.
But you may need to create lists as part of a business process, within a workflow, or within an event handler.
Shoban's link refers to list definitions. This isn't necessary if your situation requires you to, for example, just create a Links list. You can just fire in the appropriate TemplateType in this case.