Lessons in this course (11)

2. CLR, CTS, CLS — what each one does

Basic★ Must knowLesson 2 of 11

CLR responsibilities:

ComponentJob
Class loaderLoads assemblies and types, builds MethodTables
JIT compilerIL → native code
Garbage collectorAllocates and frees managed memory
Type checker / verifierType safety — no invalid casts or reading random memory
Exception managerStructured exception handling across frames and languages
Thread supportManaged threads, thread pool, synchronisation
SecurityType safety, (Framework: Code Access Security — removed in Core)
InteropP/Invoke, COM interop, marshalling
Debugging / profiling APIsDebuggers, profilers, diagnostics

CTS — the type system all languages share:

text
System.Object
├── Value types (System.ValueType): int, double, bool, char, decimal, DateTime, struct, enum (System.Enum)
└── Reference types: class, string, array (System.Array), delegate (System.Delegate), interface, record

The CTS defines visibility (public, private, internal, protected), inheritance rules (single class inheritance, multiple interfaces), members (fields, methods, properties, events) and how values are boxed. Because C# int and VB.NET Integer are both System.Int32, the languages interoperate perfectly.

CLS — the common subset for cross-language libraries. Examples of non-CLS-compliant features: unsigned types in public APIs (uint — VB.NET historically lacked them), names differing only by case (Name and name — VB.NET is case-insensitive), pointers. Mark libraries with [assembly: CLSCompliant(true)] and the compiler warns about violations.