Why would someone have
Import System
as well as
Import System.Web.UI.WebControls
If System is root of all namespaces what is the harm in just having Import System in the code behind.
Why would someone have
Import System
as well as
Import System.Web.UI.WebControls
If System is root of all namespaces what is the harm in just having Import System in the code behind.
Import System
does not import the other, lower level namespaces. Each level must be imported explicitly.
If import System
did import all of the lower-level namespaces, then there would be almost no reason to have an import at all.
But the reason we do have a namespace system is to avoid name collisions where different packages contain classes of the same names.
For example, there could be two different namespaces, (making these up) System.Secure
and System.Insecure
. Both could have the classes for dealing with http
with exactly the same names, but one could implement using secure but slower protocols, and the other insecure but quicker ones.
The developer could choose between them easily, without having to rename references all over the code. Or the code could be switched more easily at runtime, using reflection.