1

In each my .cs file I have tons of "using" lines including other namespaces, like that:

using Game.Models.Main;
using Game.Models.DataStore;
using Game.Manager.MapManager;
using Game.Network.Player;

What if in the beginning of every new .cs file I include "using" statements for all existing namespaces in my code? Are there any downsides of that? Like performance or anything I can't think of?

Why I want that: in Eclipse you can press Ctrl+Space and you'll see the list of definitions starting with the typed characters. In Visual Studio however, you can see that only if the class you're typing is among the "using" namespaces. So when you write a new class you have to type every other class name in full.

4
  • This is simple - Keep only usings which are required Commented Dec 4, 2012 at 19:56
  • 2
    As long as you know the name of the function you want to use, you can right-click it, click Resolve, and Visual Studio will include the file for you. I would advise you not to include every library under the sun, because it will (probably?) take much longer to compile. Commented Dec 4, 2012 at 19:59
  • @MadHenchbot include the file or the namespace? Files are usually included as references in the project and can contain multiple namespaces. The OP seems more concerned with using namespaces. Commented Dec 4, 2012 at 20:12
  • Yes, I know about the "resolve" thing, but it only works when you've typed the whole thing, and it requires use of the mouse which is inconvenient Commented Dec 5, 2012 at 20:22

3 Answers 3

4

It would probably slow down visual studio's intellisense, but as for a compiled product, it would not affect the resulting binary by having superfluous using statements.

If you want to remove superfluous using statements then you can right-click on the using statements, and go to "refactor" > "sort and remove"

Sign up to request clarification or add additional context in comments.

Comments

4

There is not much downside except if you ever have classes with the same name in different namespaces (like Color in System.Drawing.Color and System.Windows.Media.Color) than adding all namespaces can either cause compile errors or complete change of behavior of the code.

Comments

1

Normally you only want to include the namespaces you are using. This way you can avoid naming collisions and programmer confusion.

As far as IntelliSense is concerned, if you want something from another name space just start typing in the namespace, IntelliSense will list the namespaces and so you can drill down to what you are looking for.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.