C# Playground

Write and run real C# 14 in your browser, with IntelliSense, even offline.

Runs in your browser — nothing is uploaded

  

Real C#, in the page

This playground runs Roslyn, the official C# compiler, on the .NET 10 runtime compiled to WebAssembly. Your program is compiled into an assembly and executed right here, so the language is exactly the C# you write everywhere else: top-level statements or a classic Main, async Main with await, records and with-expressions, pattern matching with switch expressions and list patterns, LINQ query and method syntax, generics with constraints, collection expressions with spreads, primary constructors, and C# 14 extension members.

Each run loads a fresh copy of your program, so static fields start over every time. Output appears as it is written, and Stop ends even a program that loops forever.

Errors and completion as you type

The compiler checks your code continuously. Errors are underlined in red and warnings in yellow — an unused variable, a possible null dereference — with the compiler's own message and code, such as CS0029 for a type mismatch. If you press Run with errors, the output lists them in the familiar file(line,column) format and nothing runs.

Completion comes from Roslyn's own completion service, the engine behind IntelliSense. Type a dot after a string and you get its methods along with LINQ's, each with its signature and documentation; your own classes, records and methods appear too.

Built for practice

Use it to try an idea, check how a LINQ operator behaves, explore a new language feature or practise for an interview with the Exercises menu, without installing an SDK. The Examples menu has short programs for many modern features, and every one runs as a starting point for your own. When an uncaught exception ends a program, you see its type, message and a stack trace pointing at the exact lines of your code.

Practise with exercises

There are 45 exercises in four groups. Beginner ones cover string interpolation, char methods, tuples, dictionaries, lists, switch expressions, the null operators and string.Join. Intermediate ones cover classes and validation, records, interfaces, generic methods, LINQ, extension methods, custom exceptions with when filters, yield iterators, delegates and pattern matching. Advanced ones cover async/await with Task.WhenAll, IDisposable, generic constraints, operator overloading, custom enumerators, events and Span<T>. The Interview group has 20 classic problems in Easy, Medium and Hard, from two sum and valid parentheses to an LRU cache, course scheduling, Dijkstra's shortest paths and edit distance.

Check compiles a hidden test file with your code — your program's own demo doesn't run — and lists every test and case as ✓ or ✗ with its message. If your code doesn't compile, or the tests can't find a method the task asks for, Output says so. Interview problems state the complexity to aim for, and 12 of the 20 have a timing test on a large input that rejects an answer of the wrong complexity with a "Too slow" message. The timing check has a wide margin, so it catches the wrong complexity class, not small differences in speed — the exercises are for practice, not a proctored test. Check takes a few seconds because the C# compiler runs in your browser, and you still write one file. Solved exercises get a tick, and your code and progress stay in this browser.

How to use

  1. Type or paste C#, or pick an example.
  2. Watch errors and warnings underline as you type; use Ctrl+Space for completion.
  3. Press Run (Ctrl/⌘+Enter in the editor) to compile and see the output.
  4. Open Exercises to practise: read the task, write the code, and press Check to run its hidden tests — every test shows ✓ or ✗ with its message.

FAQ

Is this the real C# compiler?

Yes. It is Roslyn, the same compiler Visual Studio and the dotnet command use, running on Microsoft's .NET 10 runtime compiled to WebAssembly. Programs compile to a real assembly and run against the .NET base class library: LINQ, collections, async/await, records, generics, regular expressions, System.Text.Json, LINQ to XML and hashing behave as they do on your machine. What a browser tab can't do — start threads or processes, block while waiting, reach the network — gets a plain explanation instead of a raw runtime error.

Which C# version?

C# 14, the latest language version, including collection expressions, primary constructors, extension members and the field keyword. The runtime underneath is .NET 10, so the base class library is the current one too.

Does it work offline?

Yes, after one visit. The first time you open the page your browser downloads the compiler and runtime, about 18 MB, and keeps them. From then on the editor, completion, errors, running and checking exercises all work with no connection. The status bar shows "Available offline" once everything is stored.

Is my code uploaded?

No. Your code is compiled and run in a background worker inside this browser tab, and saved only in your browser's local storage so it survives a reload. Programs can't reach other sites or send your data anywhere off this site, either.

Why doesn't .Result or Thread.Sleep work?

WebAssembly in the browser is single-threaded, so anything that blocks a thread while waiting — .Result, .Wait(), Thread.Sleep, waiting on a lock — cannot work. Use await instead: await Task.Delay(100) rather than Thread.Sleep(100). The playground explains this whenever it happens.

Can I use NuGet packages?

No. The playground compiles a single file against the .NET base class library, which covers collections, LINQ, text, regular expressions, JSON, dates and maths. There is no package restore and no network access.

How do I read input?

Type the lines into the stdin box before you press Run. Each Console.ReadLine() call takes the next line; when the lines run out it returns null, exactly as a real console does at the end of its input.

How do the exercises work?

Pick one of 45 exercises: 25 that practise C# itself, from string interpolation and switch expressions to records, LINQ, iterators, async/await, operator overloading and spans, and 20 classic interview problems, from two sum to Dijkstra's shortest paths. Each has a short task, starter code, hints and a reference solution. Check compiles hidden tests with your code and runs them, listing every test and case as passed or failed with a message such as "Expected [0, 1] but was [1, 0]". Twelve of the 20 interview problems also time your answer on a large input, so an answer of the wrong complexity class fails with a "Too slow" message that names the complexity to aim for. The timing check has a wide margin, so it catches the wrong complexity class, not small differences in speed or a slow device — the exercises are for practice, not a proctored test. Check takes a few seconds because the C# compiler runs in your browser, and you still write one file. Solved exercises get a tick, and your code for each one is saved in this browser, so you can come back to it later, even offline.

Related tools