Skip to content

C# Implicit Usings — Complete Guide

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about C# Implicit Usings. We cover key concepts, practical examples, and best practices.

You create a new .NET 6+ console app, open Program.cs, and notice there are no using System; lines — yet Console.WriteLine works. Implicit usings automatically import common namespaces based on your project SDK.

Without implicit usings

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Console.WriteLine("Hello");

Output: "Hello" — but you had to add four using lines.

With implicit usings (default in .NET 6+)

Console.WriteLine("Hello");

Output: "Hello". The SDK generates a hidden GlobalUsings.cs with the appropriate using directives for your project type.

The auto-generated usings depend on the SDK:

SDK Auto-imported namespaces
Microsoft.NET.Sdk System, System.Collections.Generic, System.IO, System.Linq, System.Threading, etc.
Microsoft.NET.Sdk.Web Above + System.Net.Http, Microsoft.AspNetCore.*
Microsoft.NET.Sdk.Worker Above + Microsoft.Extensions.*

Prevention

  • Keep implicit usings enabled (default) for new projects.
  • Disable with <ImplicitUsings>disable</ImplicitUsings> in .csproj if you prefer explicit control.
  • Add global using for namespaces not covered by implicit usings.
  • Use <Using> items in .csproj to add custom implicit usings without code.
  • Be aware that different SDKs import different namespaces — test when switching SDK types.
  • Use dotnet new console — the template uses implicit usings by default.

Common Mistakes with implicit using

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world CSHARP code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

Can I see what implicit usings are generated?

Yes. Build the project and look in obj/<config>/<target>/<project>.GlobalUsings.g.cs — a generated file with all implicit usings. You can inspect it to see exactly what is imported.

Can I add my own implicit usings via the project file?

Yes. Add <Using Include="MyApp.Data" /> inside an <ItemGroup> in .csproj. These are treated as implicit usings and apply to all files without using the global modifier in code.

Do implicit usings slow down compilation?

Negligibly. The usings are resolved at compile time and only the ones actually used affect name resolution. Importing extra namespaces does not bloat the output assembly — unused using directives are free.

Implicit usings are enabled in all DodaTech projects. For more .NET tips, visit DodaTech.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro