确实“使用”提供什么优势?

发布于 2024-09-27 00:55:15 字数 102 浏览 0 评论 0原文

当您引用某些方法时,您可以使用 using 或显式键入整个命名空间。使用一种方法相对于另一种方法是否有任何速度优势,或者它只是为了让输入整个命名空间变得更容易?谢谢

When you reference certain methods, you can either use using or explicitly type in the entire namespace. Are there any speed advantages of using one method over the other, or is it simply there to make typing out the entire namespace easier? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甩你一脸翔 2024-10-04 00:55:18

我们都忘记了扩展方法吗?据我所知,如果没有 using 命名空间指令,它们就无法被拉入范围。

Are we all forgetting about extension methods? They cannot be pulled into scope without a using namespace directive, as far as I know.

居里长安 2024-10-04 00:55:17

运行时没有区别。

在 .NET 元数据中,类型始终使用包含命名空间的全名来表示,因此 C# 中的 using 指令将在编译程序时消失。

namespace 内部或外部编写 using 时,有一些微妙的方面(在编译时)(参见示例 这个问题),但这也只是一个编译时问题。

There is no difference at runtime.

In the .NET meta-data, a type is always represented using a full name that includes the namespace, so the using directive known from C# will disappear when a program is compiled.

There are some subtle aspects (at compile time) when it comes to writing the using inside or outside of a namespace (see for example this question), but that's also only a compile-time issue.

苦妄 2024-10-04 00:55:17

这纯粹是一个语法问题,并且被编译成同样的东西。查看每个生成的 IL。

It's purely a syntactic matter and is compiled to the same thing. Take a look at the IL produced by each.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文