Understanding the architecture of .NET is fundamental to building robust, scalable, and maintainable applications. This section delves into the core components and design principles that underpin the .NET ecosystem.
The Common Language Runtime (CLR) is the execution engine of .NET. It provides the fundamental services that manage the execution of .NET applications, including memory management, thread management, security, and exception handling. Key features include:
When you compile a .NET program, the source code is converted into Intermediate Language (IL), also known as Common Intermediate Language (CIL). This platform-agnostic language is then further processed by the CLR.
// Example of C# code that would be compiled to IL
public class HelloWorld
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello, World!");
}
}
.NET applications are often referred to as "managed code" because their execution is supervised by the CLR. This management provides the benefits of memory safety, security, and automatic resource management.
The Base Class Library (BCL) is a comprehensive collection of reusable types (classes, interfaces, value types, enumerations) that developers can use to build .NET applications. It provides functionalities for a wide range of tasks, such as:
The BCL is organized into namespaces, with the most fundamental ones being under System
and System.Collections
.
For more details, see the .NET API Reference.
The Common Type System (CTS) defines how types are declared, used, and managed in the .NET environment. It ensures that all languages that target .NET can interoperate seamlessly. The Common Language Specification (CLS) is a subset of the CTS that defines a set of rules that languages must follow to ensure interoperability.
.NET provides a consistent runtime environment across different operating systems and devices. This unified platform allows developers to write code once and deploy it on various targets, including Windows, macOS, Linux, Android, iOS, and embedded systems.
Note: This is a conceptual representation. Actual architecture involves more detailed components.
.NET supports various architectural patterns, enabling developers to choose the best approach for their specific needs: