gpt4 book ai didi

c# - 编译器以什么顺序搜索命名空间/二进制文件以查找变量名?

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:00 24 4
gpt4 key购买 nike

我只是好奇它是如何工作的。似乎找不到太多细节。可能在我的搜索中没有正确地措辞问题。但基本上,编译器如何解析名称?它以什么顺序搜索 C# 文件开头的 using 语句中列出的 namespace ?

最佳答案

按照指定的顺序。 using 指令实际上是“愚蠢的”,因为编译器会尝试在您添加的每个命名空间前加上 using over unqualified types。如果没有完全限定的类型匹配,则会出现未找到错误。如果有多个匹配项,则会出现类型不明确的错误。

来自 CLR Via C#第三版(链接到第四版):

Using the C# using directive is entirely optional; you’re always welcome to type out the fully qualified name of a type if you prefer. The C# using directive instructs the compiler to try prepending different prefixes to a type name until a match is found.

关于c# - 编译器以什么顺序搜索命名空间/二进制文件以查找变量名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18133571/

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