I\'m trying to understand the internal access modifier in C#. I can\'t seem to understand what an assembly is exactly, and what part of my program is held inside that assemb
People are easily confused by the namespace/assembly thing, as it decouples the concept of where your code is physically located (the assembly) and how you reference it (logically reference is by using the namespace and physical reference is by referencing the assembly).
I usually explain this using the word contribute
:
An assembly can contribute to multiple namespaces.
For instance, the System.Data.dll
assembly contributes to namespaces like System.Data
(e.g. the class System.Data.DataTable
) and Microsoft.SqlServer.Server
(e.g. the class Microsoft.SqlServer.Server.SqlContext
).
Multiple assemblies can contribute to a single namespace.
For instance both the System.Data.dll
assembly and the System.Xml.dll
assembly contribute to the System.Xml
namespace.
Which means that if you use the System.Xml.XmlDataDocument
class from your project, you need to reference the System.Data.dll
assembly.
And if you use the System.Xml.XmlDocument
class, you need to reference the System.Xml.dll
from your project.
(the above examples are .NET 4.0, but likely hold for previous .NET versions as well).
Danny Thorpe explained the concept of namespace
and internal
really well, so I won't go into detail about those.
--jeroen