Difference between c# using and Java import Difference between c# using and Java import wpf wpf

Difference between c# using and Java import


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.