Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do unused usings in .net affect performance? [duplicate]

Possible Duplicate:
Why should you remove unnecessary C# using directives?
How is performance affected by an unused using statement

Do unused usings in c# affect runtime performance? If yes, How do so?

using System;
using System.Collections.Generic;
using System.ComponentModel; -----//Unused
using System.Data;---------------//Unused
using System.Drawing;-----------//Unused
using System.Text;-------------//Unused
using System.Windows.Forms;
using System.Threading;------//Unused
using System.Linq;----------//Unused
using System.IO;-----------//Unused
using System.Diagnostics;-//Unused
using System.Data.OleDb;
using OBID; 
like image 353
Vaibhav Jain Avatar asked Aug 19 '12 13:08

Vaibhav Jain


People also ask

Do unused using statements affect performance?

An unused using has no impact to the runtime performance of your application.

Why remove unused usings?

Removing unused namespaces will reduce the number of autocompletion candidates in your text editor as you type.

Is using system required?

No you don't need using system. It just assumes that you may need the classes from system, since there are many useful ones. You can remove it if you're not using classes such as Random.


1 Answers

NO, but It effects the IDE performance and the compilation process of your project. I can give you a short example. If you have ever used coderush http://devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/ which is from devexpress, their IDE optimizer and code optimizer will also suggest you to remove unused namespaces.

Update: Here is more use information from Dmitriy's Blog There are few reasons why you should remove unused usings in you C# code.

•It is useless code, that just creates clutter in your source code and it also confusing for the developer because you don’t know which namespaces are actually used.
•Over time as your code changes it can accumulate a lot of unused using statements which create even more clutter in you code.
•It can make your compiling faster, since compiler does not have to look up all those extra unused namespaces.
•It will help avoid name conflict with new items that you going to add to your solution if both of those have same names.
•It will reduce number of items in your Visual Studio editor auto completion

There are couple ways to remove those unused usings, you can do it individually on each file

http://msdn.microsoft.com/en-us/library/bb514115.aspx

You also can download plugin called batchFormat for Visual Studio 2010 that can help you to remove all unused usings for the whole project.

http://www.addictivetips.com/windows-tips/batch-format-remove-unused-usings-and-format-visual-studio-document/

like image 139
Idrees Khan Avatar answered Oct 23 '22 14:10

Idrees Khan