Vadzim Savenok Vadzim Savenok - 1 year ago 105
C# Question

How C# handles workload with using statement?

I am currently cleaning up the code for my project and trying to improve its performance. As a part of improvement, I thought of removing unused "using" statements from all files. I would like to figure out if that would indeed improve the performance, so here is my question.

Through the "using" statement, is an external library/resource loaded when any method from the file is executed (READ: When file itself is loaded) OR the external library is loaded only when calling a specific method is actually using this library?

Answer Source

The using statement is purely syntactic sugar; it lets you skip writing the namespace when using types in that namespace.

It has no effect whatsoever on the compiled IL or runtime performance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download