What is the difference between a namespace and an assembly?
Quick Answer
A namespace is a logical grouping of type names to avoid clashes and organise code — purely a naming device, resolved at compile time. An assembly is the physical deployment unit — a compiled .dll/.exe with its own version and identity. One assembly can contain many namespaces; one namespace can span many assemblies.
A namespace is just a way to organise type names and prevent collisions — it's a compile-time concept, nothing physical. An assembly is the actual compiled artifact, a DLL or EXE, and it's what gets versioned and deployed and referenced. They're independent: one assembly can hold dozens of namespaces, and a namespace like System.Collections.Generic is actually implemented across several different framework assemblies.
System.Collections.Generictypes live across several framework assemblies.- A
usingdirective imports a namespace; aPackageReference/project reference brings in an assembly. - File-scoped namespaces (
namespace X;) reduce nesting in modern C#. - Namespace ≠ folder, but matching them is a strong convention.