Difference between c# using and Java import

一个人想着一个人 提交于 2019-11-30 13:59:12

What the Java import does what .NET is called a reference - adding a reference to an assembly in .NET allows you to use the (public) types defined in that assembly.

The C# using directive is simply a way to access these types without typing out the whole namespace.

You can also use the directive to provide namespace aliases.

In Java, without *, you have to import individual classes. In C#, using directives are for namespaces (but not any sub-namespaces, i.e., using System; doesn't get you System.Windows.Forms). So, import java.awt.* is giving you about the same as using System.Windows.Forms, so there's not really a need for * in .Net.

Be clear about what Java's import is doing. In spite of the name, no .class files are being loaded. All you're doing is saving yourself typing. Java import allows you to refer to a class using its short name instead of its fully-resolved class name (e.g. String instead of java.lang.String).

C# using is different from Java import if it actually adds something to an assembly. Java .class byte code is loaded as needed by the class loader, not before.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!