Reputation: 4104
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...?
Upvotes: 9
Views: 7523
Reputation: 40818
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.
Upvotes: 13
Reputation: 53958
Nope inside an assembly you may have define more than one namespaces. An assembly is the smallest unit of deployment in .NET. It is a collection of your IL code and metadata about you code. It contains a file called Manifest in which all the types that are used in your assembly or referred to are declared. Also there are some other files.
As it is stated more formally in MSDN:
Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.
On the other hand for a namespace
we have that
The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.
as it is stated in MSDN
From the above it is clear that you can declare as many namespaces you want inside an assembly.
A nice and free tool that you can use to see what is in an assembly is the IL Disassembler.
Upvotes: 4
Reputation: 12603
In the .NET world, Assembly is a package of compiled code. It can be either an executable(.exe
file) or a shared library(.dll
file) and can contain multiple namespaces.
Upvotes: 1
Reputation: 152521
Internal classes are not necessarily visible to all classes within the same namespace, since a namespace can span multiple assemblies. The assembly is the compiled file (DLL or EXE).
Usually it means within the same project, but there are methods to combine the output of multiple projects into one assembly (via ILMERGE).
Upvotes: 1
Reputation: 28829
An assembly is a physical container file (DLL or EXE).
Although somewhat unusual, a namespace can span multiple assemblies.
Upvotes: 1
Reputation: 3255
An Assembly is a Project that has been compiled into a .DLL or .EXE. For the purposes of Visual Studio, any Class Library project, or Windows Forms App, or WPF App will compile into an Assembly.
Upvotes: 6