Reputation: 2444
I recently stopped using using-statements and instead use the full namespace path of any .net object that I call.
Example:
using System;
namespace QuizViewer
{
class Class1
{
Console.WriteLine("Hello World!");
}
}
This is what I do now.
namespace QuizViewer
{
class Class1
{
System.Console.WriteLine("Hello World!");
}
}
Before you ask why I do this, I am using this style so that I can see exactly where my objects are coming from and it's easier when using the different Timer objects and other objects with similar names.
Is there any performance increase or decrease in this style of programming?
Upvotes: 22
Views: 8908
Reputation: 568
If you disassemble both of this pieces of code and look at IL code, you'll find that compiler always references all the types by it's full names. That is absolutely identical ways to operating types.
Upvotes: 1
Reputation: 180944
There is zero performance difference because the compiler ALWAYS puts in the full name - using is only a hint for the compiler, the runtime doesn't know or support that.
However, once you memorize where the objects come from you will look at this as silly and verbose. There is just so much noise and people just know that Path is from System.IO, Console is in System and StringBuilder is in System.Text.
One downside of your approach: Without using, no extension methods outside of the current namespace. Have fun writing System.Linq.Enumerable.Where(inputSequence,...)
instead of just inputSequence.Where(...)
:)
Upvotes: 41
Reputation: 2799
The only performance hit, is the hit you take to type it all out, and with you or others reading it.
Using statements are to help readability, not really for performance.
Upvotes: 5
Reputation: 59020
There's no performance impact; it's mostly a stylistic choice. I find that using using
statements reduces the clutter. Plus, with Intellisense, it's easy enough to see the fully qualified namespace.
Upvotes: 5
Reputation: 5340
I think that this style result in a programmer performance decrease :). I use the using statement and usually it is clear from code to which namespace the class belong. If not, press F12.
Just my 2c.
Upvotes: 6