At runtime it will not matter if you have unused using directives in your code or not.
The using directive is available for convenience so you can write
using System.IO; [...] string path = Path.GetDirectoryName(filename);
instead of writing the full name
string path = System.IO.Path.GetDirectoryName(filename);
every time you want to use a type from the System.IO namespace. The directive tells the compiler that namespaces should look for the types used in the file. Then the compiler will actually replace the first example with the second, that is, the IL code in the assembly will always use fully qualified type names. Unused namespaces will not be displayed in the compiled assembly.
However, there are reasons to keep a clean list of imported namespaces. John Faminella stated in a related question :
There are several reasons why you would like to take them out.
- It's pointless. They do not add value.
- This is confusing. What is used in this namespace?
- If you do not, you will gradually accumulate meaningless use with code change time.
- Static analysis is slower.
- Code compiles faster.
source share