views:

697

answers:

3

Why does Visual Studio 2008 automatically insert the following using directives into each new C# file I create?

using System; 
using System.Collections.Generic; 
using System.Text;

What's so special about these namespaces? Are these the most frequently used ones?

+16  A: 

Yes, they're frequently used, that's all, so MS put them in the Visual Studio templates. Personally I use "sort and remove unused usings" pretty frequently, so they often go away.

If you want to remove them, you can amend the "new class" template.

EDIT: If you become a fan of "Sort and Remove Unused Using Directives" you should get hold of PowerCommands for Visual Studio - that adds a Solution Explorer context menu item to do it for a whole project instead of just one file :)

Jon Skeet
+2  A: 

If you like, you can change them. See here for more info.

Andrew Flanagan
+1  A: 

That's the namespaces that was selected to be in the template for a new file, in that specific type of project. Different types of projects have different templates and thus different sets of using directives. The using directives were just chosen depending on what's needed for that type of file, and what you are likely to use.

The using directive only tells the compiler where to look for classes, so there is no harm in having using directives that is not neccesarily needed by the code, as long as they don't cause any conflicts (ambiguous class names).

If you right click in the file and open the Organise Usings submenu, you find the option Remove Unused Usings that you can use to remove using directives that it not needed in the file.

Guffa
Well, there's harm in terms of readability I'd say. I think it's a good idea to keep the list of using directives tidy - hence the goodness of Remove Unused Usings (and the Sort and Remove version too).
Jon Skeet