gpt4 book ai didi

c# - 在 c# 项目中移动文件时是否必须更改命名空间

转载 作者:行者123 更新时间:2023-12-04 16:57:35 25 4
gpt4 key购买 nike

我正在移动项目中的文件,但找不到明确的答案 - 命名空间是否与文件位置相关?移动文件时是否需要更改命名空间?

最佳答案

is namespace connected with location of the file?



只能按惯例。它不是必需的,也不是由编译器或运行时强制执行的。

请注意,在 C# 中,您可以嵌套命名空间,并且可以在任何给定的嵌套级别声明多个命名空间。显然,文件中只有一个声明的命名空间才能真正匹配文件的位置。因此,在不放弃 C# 中的这些功能的情况下,甚至不可能要求命名空间与文件名匹配。

Do I need to change namespace when moving files?



不,见上文。

您可能对有关该主题的相关 Stack Overflow Q&A 感兴趣:
  • How to make the C# namespace work like Java Packages so they rename automatically when moving them?
  • How do I fix Visual Studio (2013) namespace collision when moving files
  • Should the folders in a solution match the namespace?

  • 前两个与更改源文件位置时的文件和命名空间管理有关,而第三个则更多地与普遍接受的约定有关。

    关于c# - 在 c# 项目中移动文件时是否必须更改命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34121845/

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