gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:28:27 26 4
gpt4 key购买 nike

来自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?

如果有package语句,它一定是你的Java源代码的第一行。这意味着您的问题的答案是“否”:每个 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

关于java - Java包和C#命名空间的一些比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46615645/

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