Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a namespace an assembly, or a project?

Tags:

c#

.net

Just reviewing some .NET stuff for an interview tomorrow,

MSDN defines the Internal keyword as follows:

Internal types or members are accessible only within files in the same assembly

But what I cannot seem to find is the definition for an assembly. Is that everything within the same namespace, the same project, or...?

like image 652
sab669 Avatar asked Dec 26 '22 05:12

sab669


1 Answers

Assemblies and namespaces are orthogonal. One assembly may contain multiple namespaces and a single namespace may span multiple assemblies. Assemblies are the smallest independently versionable unit of code in the .NET framework. Assemblies define the physical organization of your code (into dll or exe files), while namespaces define the logical organization. A single assembly is a single dll or exe file. A namespace is logical grouping typically based on technology or function. System.Net deals with networking. System.Text deals with text manipulation and encodings.

Note that I haven't mentioned projects at all. A project is something that is only really relevant to a particular build system. The .NET runtime has no knowledge of projects, per se. Since most people use Visual Studio and MSBuild tools for development and the default is to have a single project output a single assembly, people tend to use the terms project and assembly interchangeably in casual conversation. Other tools like MonoDevelop follow a similar pattern, but there is no rule dictating that a single project must produce a single assembly.

like image 111
Mike Zboray Avatar answered Jan 05 '23 09:01

Mike Zboray