gpt4 book ai didi

c# - c# Using Directive 会影响对象大小吗?

转载 作者:行者123 更新时间:2023-11-30 15:43:21 26 4
gpt4 key购买 nike

换句话说,以下是否有所不同:

这个:

using a;
using b;
using c;

public class foo {
public void doStuff() {
// do some stuff utilizing classes from a, b, and c.
}
}

与此相比:

public class foo {
public void doStuff() {
bar.doStuff();
}
}

连同:

using a;
using b;
using c;

public static class bar {
public static void doStuff() {
// do some stuff utilizing classes from a, b, and c
}
}

假设 foo 是一个被广泛使用和传递的类,经常被序列化/反序列化等。但是 doStuff() 方法很少被调用。将其分解为上面的第二个/第三个片段是否有任何性能优势?

最佳答案

没有。 using 只是关于您可以在出现 using 声明的源文件中使用哪些简单名称。

基本上,using N; 对编译器说“嘿,如果我在这个源文件中键入简单名称 Foo,而你找不到任何名为 Foo 范围内,你能检查命名空间 N 中是否有任何名为 Foo 的东西吗?”谢谢!

也就是说,您可以不使用 using 并通过它的完全限定名称引用所有内容,并且您根本没有更改编译器的 IL 输出。

Is there any performance advantage at all in breaking it out into the second/third snippets above?

根据上面的解释,没有。

关于c# - c# Using Directive 会影响对象大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6749915/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com