Lesson 13 of 30
Namespaces and Assemblies
C# in Visual Studio 2026 — a hands-on guide for developers at every level.
Namespaces
Namespaces organise code into logical groups and prevent name collisions. Every type in .NET lives inside a namespace.
namespace MyApp.Utilities
{
public class MathHelper
{
public static int Double(int n) => n * 2;
}
}
C# 10+ supports file-scoped namespaces which removes one level of indentation:
namespace MyApp.Utilities; // no curly braces needed
public class MathHelper
{
public static int Double(int n) => n * 2;
}
using Directives
using System.Collections.Generic;
using System.Linq;
using MyApp.Utilities;
var result = MathHelper.Double(21); // 42
Global usings (C# 10+)
Put global usings in a single file (e.g. GlobalUsings.cs) to apply them across the whole project:
global using System;
global using System.Collections.Generic;
global using System.Linq;
Assemblies and Projects
A compiled C# project produces an assembly — either a .dll (library) or an .exe (executable). A Solution (.sln) can contain multiple projects that reference each other.
💡 Tip
In Visual Studio, right-click a project → Add → Project Reference to share code between projects in the same solution.