Importing Namespace

Learn about the namespaces in C# and how to import them, including implicit and global namespace imports and project settings in .NET 6 and C# 10.

System is a namespace, like an address for a type. To refer to someone’s location strictly, we might use Oxford.HighStreet.BobSmith, which tells us to look for a person named Bob Smith on the High Street in Oxford. System.Console.WriteLine tells the compiler to look for a method called WriteLine in a type named Console in a namespace named System.

To simplify our code, the Console App project template for every version of .NET before 6.0 added a statement at the top of the code file to tell the compiler to always look in the System namespace for types that haven’t been prefixed with their namespace, as shown in the following code:

Press + to interact
using System; // import the System namespace

We call this importing the namespace. The effect of importing a namespace is that all available types in that namespace will be available to our program without needing to enter the namespace prefix and will be seen in IntelliSense. At the same time, we write code. .NET Interactive Notebooks have most namespaces imported automatically.

Implicitly and globally importing namespaces

Traditionally, every .cs file that ...