using语句VS命名空间的路径? C#语句、路径、空间、using

2023-09-02 01:30:50 作者:誰與我狂

我最近使用使用说明,并改用我调用任何.NET对象的完整的命名空间路径停止。

I recently stopped using "using statements" and instead use the full namespace path of any .NET object that I call.

例如:

using System;    

namespace QuizViewer
{
    class Class1
    {
        Console.WriteLine("Hello World!");
    }
}

这就是我现在做的。

namespace QuizViewer
{
    class Class1
    {
        System.Console.WriteLine("Hello World!");
    }
}

在你问我为什么这样做,我现在用的这种风格,这样我可以清楚地看到我的对象是来自和它使用不同的Timer对象,并具有类似名称的其他对象时更容易。

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 its easier when using the different Timer objects and other objects with similar names.

有任何性能增加或减少了这种编程风格?

Is there any performance increase or decrease for this style of programming?

推荐答案

有为零的性能差异,因为编译器总是把在全名 - 使用只是一个提示编译器,运行时不知道或不支持的

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.

然而,一旦你记住了那里的对象来自你看这是愚蠢的,冗长。只是有这么多的噪音,人们只知道这条道路是从System.IO,控制台是在系统和StringBuilder的是System.Text。

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.

你的方法的一个缺点:如果不使用,目前的命名空间以外的任何扩展方法。玩得开心写 System.Linq.Enumerable.Where(inputSequence,...)而不仅仅是 inputSequence.Where(...):)

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(...) :)