在C#中的命名空间和包在Java中的区别 [英] Difference between namespace in C# and package in Java
问题描述
什么是Java中的C#命名空间和包之间的差值(使用方面)?
What is the difference (in terms of use) between namespaces in C# and packages in Java?
推荐答案
从:<一href=\"http://www.javacamp.org/javavscsharp/namespace.html\">http://www.javacamp.org/javavscsharp/namespace.html
包用于组织文件或公共类型以避免类型冲突。包构建体可以被映射到一个文件系统。
Packages are used to organize files or public types to avoid type conflicts. Package constructs can be mapped to a file system.
System.Security.Cryptography.AsymmetricAlgorithm aa;
可能被替换:
import System.Security.Crypography;
class xxx { ...
AsymmetricAlgorithm aa;
有对包没有别名。你必须使用import语句或完全限定点名的具体类型。
There is no alias for packages. You have to use import statement or fully-qualified name to mention the specific type.
package N1.N2;
class A {}
class B {}
或
package N1.N2;
class A {}
另外一个源文件:
Another source file:
package N1.N2;
class B {}
包不能嵌套。一个源文件只能有一个包语句。
Package cannot be nested. One source file can only have one package statement.
命名空间用于组织程序,无论是作为一个程序的内部组织体系,并作为外部组织体系。
Namespaces are used to organize programs, both as an "internal" organization system for a program, and as an "external" organization system.
System.Security.Cryptography.AsymmetricAlgorithm aa;
可能被替换:
using System.Security.Crypography;
AsymmetricAlgorithm aa;
替代地,人们可以在该命名空间中指定的别名,例如
Alternatively, one could specify an alias for the the namespace, eg
using myAlias = System.Security.Crypography;
,然后参照类
myAlias.AsymmetricAlgorithm
namespace N1.N2
{
class A {}
class B {}
}
或
namespace N1
{
namespace N2
{
class A {}
class B {}
}
}
这篇关于在C#中的命名空间和包在Java中的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!