Reputation: 11287
In Visual Studio there is a command to remove unused using statements
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Is there a performance hit for having unused usings?
Upvotes: 17
Views: 3911
Reputation: 754705
The number of namespaces used in code files does not impact the runtime performance of the application. It does have an impact on compile time as the compiler must search those namespaces for additional items such as types and extension methods.
The only runtime impact the number of namespaces I'm aware of are
Upvotes: 10
Reputation: 8647
I'm sure there is a performance hit somewhere (probably during compilation) but its probably negligible. Either way, I'd recommend running that command - it will remove that potential performance hit and make your code easier to read and maintain. And it'll remove unused namesapces from intellisense, making it easier to code :)
Upvotes: 0
Reputation: 164291
There is no performance hit for unused using statements. They only need evaluation at compile time.
Upvotes: 1
Reputation: 29468
No. Namespaces are used to resolve class names at compile time. After compilation, your assembly only contains fully qualified class names like System.Collections.Generic.List<int> myList = new System.Collections.Generic.List<int>()
, all the usings are gone.
Upvotes: 5
Reputation: 19781
It only affects compilation times when the compiler needs to iterate the namespaces to find the referenced types. (And that aint much anyway.) It wont affect runtime performance at all.
Upvotes: 4