This completes the Namespaces & Code Organization section by showing how code is packaged and distributed.
π 1. What Is an Assembly?
-
An assembly is the compiled output of C# code β usually a
.exe
or.dll
file. -
It is the building block of .NET applications.
-
Contains:
-
IL code (Intermediate Language) β the compiled C# code.
-
Metadata β info about types, members, references.
-
Manifest β info about version, culture, dependencies.
-
-
DLL (Dynamic Link Library) = library assembly (no standalone execution).
-
EXE = executable assembly (can run directly).
π 2. How Namespaces Relate to Assemblies
-
Namespaces group types logically in code.
-
Assemblies group compiled code physically.
-
One assembly can contain multiple namespaces, and one namespace can span multiple assemblies.
Assembly: MyApplication.dll
ββ Namespace: MyApplication
β ββ Class Program
β ββ Class Helper
ββ Namespace: MyApplication.Models
β ββ Class User
- When you reference a DLL, you gain access to all namespaces and types inside that assembly.
π 3. Referencing Assemblies
1. Via Visual Studio
-
Right-click References β Add Reference β Browse / Projects / NuGet
-
Once added, you can
using NamespaceName;
to access its types.
2. Via .NET CLI
dotnet add reference ../MyLibrary/MyLibrary.csproj
- Then in code:
using MyLibrary.Utilities;
π 4. Benefits of Assemblies
-
Code reuse β share compiled libraries across multiple projects.
-
Versioning β different assemblies can have version info.
-
Encapsulation β hide internal implementation; only public types are accessible.
-
Modularity β large projects can be split into multiple DLLs.
π 5. Key Points
Feature | Notes |
---|---|
Assembly | Compiled unit (.exe or .dll) |
Manifest | Metadata + version info |
DLL | Library assembly (cannot run standalone) |
Namespace | Logical grouping of types (may span assemblies) |
Reference | How a project gains access to another assembly |
NuGet | Package manager to distribute assemblies easily |
π 6. Analogy
-
Namespace = folder with related files
-
Assembly = ZIP archive containing folders (namespaces)
-
DLL = library ZIP (cannot run alone)
-
EXE = runnable ZIP (application)
β Summary:
-
Assemblies are physical compiled units in .NET.
-
Namespaces are logical groupings of types inside assemblies.
-
Understanding assemblies is key for code reuse, modularity, and referencing external libraries.
Next, if you like, we can create a complete βNamespaces & Code Organizationβ mini-section for your guide, combining:
-
namespace
-
using
/global using
-
extern alias
-
Assemblies & DLLs