Sorry if this question was asked already.
I started studying C# and noticed that C# doesn’t automatically import nested namespaces.
I don’t understand:
using System;
should automatically import all classes contained in the System namespace right?
So there should be no need for me to write
using System.Windows.Form;
I would understand if using Windows.Form even worked. But the compiler could not resolve it! What is the point of the using System; before it then?
So why does using System; not import System.Windows automatically as well as System.Windows.Forms – sorry if the word import is wrong here.. maybe move to global namespace is the right terminology.
C# is not Java.
A
usingdirective is used so you don’t have to type in the fully qualified name of a type. It also helps with disambiguating type names (using aliases for instance).In the case of
Console, for example, you don’t need to typeSystem.Console.It is important to understand the difference between a namespace and an assembly – a namespace is a logical grouping of types. An assembly is a physical grouping of types. Namespaces can span assemblies.
When you reference an assembly (this is more like importing a package in Java), you gain access to all of the public types in it. In order to use a type you need to uniquely identify it. This is done through the namespace – the
usingdirective simply means you don’t have to type the fully qualified name of the type.