Member-only story

How to use Global Using Directives in .NET 6

A new feature that can help reduce the amount of repetitive code across your entire project

Jamie Burns
4 min readMay 31, 2022
Photo by Arpit Rastogi on Unsplash

If you’ve written anything in C#, you’ll have come across Using Directives.

By using them (no pun intended) you can reference types within that namespace, without having to fully qualify the type name.

A quick re-cap of Using Directives

Most C# files will reference types that exist in another namespace. Without any Using Directives, these types have to be fully qualified, so that the namespace is included in the name of the type:

Here you can see the property has been defined with the type StringBuilder, and since this type is in the System.Text namespace, the type has been fully qualified and included when StringBuilder is referenced.

Usually this is refactored to use a Using Directive for that namespace, so that the namespace doesn’t need to be repeated throughout the file:

--

--

Jamie Burns
Jamie Burns

Written by Jamie Burns

Software Engineer, founder of Bungalow64 Technologies