Marcus Santodonato
Marcus Santodonato

Reputation: 136

Cost of using references to namespaces you don't need in C#

Is there any significant cost to using a reference to a namespace you don't need? I'm thinking the members probably live on the heap somewhere, tying up memory. The reason I ask is because I noticed some old references I no longer need in some production code and am wondering if it is worth refactoring in the short term.

Upvotes: 4

Views: 262

Answers (1)

SLaks
SLaks

Reputation: 887413

Not at all.

Namespaces and using statements are a purely compile-time construct.
At runtime, all references to classes and members refer to the actual member including the full namespace.
Extra using statements will have a minute impact on compile time, since the compiler will need to search more namespaces for each classname.

Unused assemblies also have no impact; assemblies aren't loaded until they're used.

Upvotes: 5

Related Questions