Zero C# is a compiler project that allows C# source code to run as standalone native programs without a .NET runtime, garbage collector, or installation requirements. Based on bflat, the project preserves C#’s syntax, type checking, and generics while handling memory through arena allocation—a strategy where memory is freed all at once rather than individually.

Developers retain most modern C# 15 features, including unions, extension members, real generics (with specialized copies per type), interfaces with virtual methods, records, tuples, anonymous types, lambdas, and limited query operations through a small library. Threading support includes Parallel.For for multicore execution. However, some runtime features are removed: there is no garbage collector, no .NET runtime, no exception catching (programs terminate on throw, with errors returned as unions), and no reflection or async/await.
Memory management differs substantially. Without a garbage collector, the new keyword never allocates; instead, arenas distribute memory and release it collectively at once. String handling avoids throwaway allocations—formatted output writes directly to buffers, and input reads into spans. Strings requiring longer lifespans are placed into arenas. Collections including List and Dict are designed to live within arenas as handles.
The project demonstrates cross-platform compilation with identical source code building for multiple targets. A minimal “Hello World” program compiles to 10.7 KB on Windows x64, 39.8 KB on Linux x64, 64.7 KB on macOS Apple Silicon, 15.8 KB as WebAssembly, and 16 KB on DOS via a 386 processor using the HX DOS extender. All builds are tested against identical test suites requiring matching output across platforms.
Memory safety rules from C# 15 are enabled by default. Pointer creation is marked as safe, and reading through pointers is explicitly noted and explained. The project includes installation via dotnet on Linux or directly from the repository for all targets, along with a tutorial covering output, input, bad input handling, and arena allocation.
Key facts
- Zero C# eliminates the .NET runtime and garbage collector, reducing binary sizes to 10–65 KB depending on platform
- The same source code compiles unchanged to Windows, Linux, macOS, WebAssembly, and DOS (386)
- Memory is managed via arenas that free all allocated memory at once rather than individually
- Most C# 15 features are preserved including generics, interfaces, records, and lambdas
- Exception handling differs: throw terminates the program, and errors return as unions instead
