Getting Started
This course sits deliberately next to Java throughout — not because the two are interchangeable, but because they share more architecture than most language pairs on this site, and diverge in specific, namable places. This chapter starts with what they share.
The CLR vs. the JVM
C# compiles to IL (Intermediate Language) — not directly to machine code — and the CLR (Common Language Runtime) JIT-compiles that IL at runtime, exactly the same two-stage model java1-1 described for the JVM and Java bytecode. This is a genuine point of similarity worth naming explicitly, not a coincidence — C# inherited this architecture on purpose, the same "write once, run wherever the runtime exists" tradeoff Java made first.
The dotnet CLI
Where java1-1 used two separate tools — javac to compile, java to run — dotnet is one unified CLI covering project scaffolding, building, and running. dotnet run alone does what javac + java together did.
Top-Level Statements
Since C# 9, a file can skip the class-and-Main boilerplate entirely for the simplest programs — a real, direct contrast to java1-1's strict "everything lives in a class, with an explicit public static void Main" requirement. Under the hood, though, the compiler still generates that exact class-and-Main shape automatically — this is real syntactic sugar over the same model, not a fundamentally different one.
What's Really There
This is the explicit, traditional form — the same shape java1-1 required from the very first line. Larger, real applications generally still write Main explicitly; top-level statements are mainly a convenience for small programs, scripts, and quick experiments.
C#'s Origin as Microsoft's Direct Answer to Java
C# was created in 2000, led by Anders Hejlsberg — previously the architect behind Turbo Pascal and Delphi, later the designer of TypeScript. Its creation followed directly from a Sun Microsystems lawsuit over Microsoft's own non-compliant Java implementation, J++ — rather than continue fighting over Java itself, Microsoft built its own language and runtime from scratch. This is real, documented history, not just a marketing framing — and it's exactly why C# and Java's architectures line up as closely as they do.
| Aspect | Java (java1-1) | C# |
|---|---|---|
| Runtime | JVM | CLR |
| Intermediate format | bytecode | IL |
| Compile & run tooling | javac, then java — two tools | dotnet — one unified CLI |
| Minimum program shape | always an explicit class + main | top-level statements allowed (C# 9+) |
Main explicitly once there's more than one entry point's worth of setup to reason about.
Main per project.
Coding Challenges
Create a new console project with dotnet new console, write a top-level-statement Program.cs that prints two lines of your choosing, and run it with dotnet run.
📄 View solutionRewrite Challenge 1's program using the explicit class Program with a static void Main(string[] args) method instead of top-level statements, and confirm it produces identical output.
📄 View solutionExplain in a comment why C# and Java both use a two-stage compile-then-JIT model rather than compiling directly to native machine code, tying your answer to C#'s own origin as a direct answer to Java.
📄 View solutionChapter 1 Quick Reference
- The CLR JIT-compiles IL at runtime — the same two-stage model as the JVM and Java bytecode (java1-1)
- dotnet is one unified CLI for scaffolding, building, and running — Java needed javac and java separately
- Top-level statements (C# 9+) skip the class/Main boilerplate for simple programs — real sugar, not a different model underneath
- Only one file per project may use top-level statements
- C# was created in 2000 as Microsoft's direct answer to Java, led by Anders Hejlsberg — later also the designer of TypeScript
- Next chapter: variables and basic types — value types vs. reference types, and var type inference