Java 包和 C# 命名空间之间的一些比较

Some comparison between Java package and C# namespace

来自Programming Language Pragmatics 4ed by Michael Scott

C# follows Java’s lead in extracting header information automatically from complete class definitions.

然后它继续提到 C# 中的命名空间与包中的不同之处 Java:

  1. Its module-level syntax, however, is based on the namespaces of C++, which allow a single file to contain fragments of multiple namespaces.

    Java是否允许单个文件包含多个文件的片段 包裹?

  2. There is also no notion of standard search path in C#: to build a complete program, the programmer must provide the compiler with a complete list of all the files required.

    C#程序员如何为编译器提供完整的 所有所需文件的列表?

谢谢。

Does Java allow a single file to contain fragments of multiple packages?

如果有包语句,它必须是你的Java源代码的第一行。这意味着您的问题的答案是 "no":每个 Java 个源文件最多可以有一个包声明。

How does a C# programmer must provide the compiler with a complete list of all the files required?

这仅适用于在命令行上构建,因为 IDE 会自动处理此问题。当您使用 csc.exe 在命令行上构建代码时,您必须通过逐个列出它们来提供组成模块的所有文件的列表,例如

csc src\File1.cs src\File2.cs src\File3.cs

或通过指定模式:

csc src\*.cs