gpt4 book ai didi

c# - 不明确的类型名称

转载 作者:太空宇宙 更新时间:2023-11-03 17:14:46 25 4
gpt4 key购买 nike

我对类型的阴影可见性有疑问。让我们假设以下代码:

namespace A {
class B {
int V1;
class A {
class B { }
void Foo() {
A.B b;
// "b" should be of the first type "B",
// but it actually points to A.B.A.B
b.V1 = 1; //Compile error
}
}
}
}

如何在声明“b”的地方声明类型为“A.B”的变量(其中“A”应该是命名空间,而不是嵌套类“A”)?

最佳答案

使用“global”关键字:

global::A.B b;

关于c# - 不明确的类型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21883084/

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