Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default using directives in new C# files

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?

like image 882
compie Avatar asked Mar 16 '09 16:03

compie


People also ask

What are using directives in C#?

The using directive can appear: At the beginning of a source code file, before any namespace or type declarations. In any namespace, but before any namespaces or types declared in that namespace, unless the global modifier is used, in which case the directive must appear before all namespace and type declarations.

What is Global :: in C#?

:: operator (C# reference) The global namespace is the namespace that contains namespaces and types that are not declared inside a named namespace. When used with the :: qualifier, the global alias always references the global namespace, even if there is the user-defined global namespace alias.

What is namespace C#?

The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types. C# Copy.

How do I add a directive in Visual Studio?

Run regedit . If you want to install the directive processor in the experimental version of Visual Studio, insert "Exp" after "11.0". Add a registry key that has the same name as the directive processor class. In the registry tree, right-click the DirectiveProcessors node, point to New, and then click Key.


1 Answers

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 :)

like image 71
Jon Skeet Avatar answered Nov 16 '22 01:11

Jon Skeet