C# Interview Question #132

What is the difference between a namespace and an assembly?

Reflection, Dynamic & Runtime Senior Advanced

Quick Interview Answer

A namespace is a logical naming mechanism used to organize types and avoid naming conflicts. An assembly is a compiled physical and deployment unit containing code and metadata.

Detailed Explanation

A namespace is a logical naming mechanism used to organize types and avoid naming conflicts. An assembly is a compiled physical and deployment unit containing code and metadata.

A namespace can span multiple assemblies, and one assembly can contain types from multiple namespaces.

For example, two different projects can both contain types under the same company namespace even though they compile into separate DLL files.

Code Example

namespace MyCompany.Products.Services
{
    public class ProductService
    {
    }
}