Console.WriteLine("Welcome to Online IDE!");
Console.WriteLine("Start coding in C#...");

Press Run or Ctrl ↵ to execute main.cs.
Type program input here while it runs.

C#

Online C# Compiler

Code compiles with Roslyn’s csc as C# 14 and runs on .NET 10, with System, System.Linq, System.Collections.Generic, System.IO and the threading namespaces already imported. Console.ReadLine() reads what you type in the console while the program runs.

Try it above

How C# runs here

Versions
C# 14 on .NET 10
Build
csc *.cs (Roslyn, with the usual global usings)
Run
dotnet main.dll
Limits per run
512 MB memory, 15 s of CPU time on half a core, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.

A program that reads input

Top-level statements need no class or Main method. This reads a count and a line of numbers:

C#
Console.Write("How many numbers? ");
int n = int.Parse(Console.ReadLine());
Console.Write($"Enter {n} numbers: ");
int[] nums = Console.ReadLine()
    .Split(' ', StringSplitOptions.RemoveEmptyEntries)
    .Select(s => int.Parse(s))
    .ToArray();

Array.Sort(nums);
Console.WriteLine($"Sorted: {string.Join(", ", nums)}");
Console.WriteLine($"Average: {nums.Average():F2}");
Terminal
$ dotnet main.dll
How many numbers? 4
Enter 4 numbers: 7 2 9 4
Sorted: 2, 4, 7, 9
Average: 5.50

Split with RemoveEmptyEntries ignores double spaces between numbers, and Average() comes from System.Linq, which is already imported.

Reading input with Console.ReadLine()

  • Console.ReadLine() returns the whole line as a string. Two numbers typed on one line make int.Parse() fail with System.FormatException: The input string '3 4' was not in a correct format. Split the line first, as above.
  • int.TryParse(Console.ReadLine(), out int n) returns false instead of throwing, which suits input you want to check and ask for again.
  • Console.Read() returns one character’s code, not a number: typing 5 gives 53. Use ReadLine() and parse it.
  • Console.ReadKey() doesn’t work, because input reaches the program as lines through a redirected stream rather than from a keyboard. A “press any key” pause isn’t needed.
  • The console can’t send end of input, so while ((line = Console.ReadLine()) != null) keeps waiting after the last line. Stop at an empty line or read a count first.
  • For many thousands of output lines, collect them in a StringBuilder (add using System.Text;) and write once.
  • Runs use invariant globalization: double.Parse("3.5") reads a decimal point and numbers print with one, whatever language your computer uses.

Several .cs files

The build is csc *.cs, so every .cs file in the playground compiles into one program. Types can live in their own files:

C#
// Shapes.cs
public record Rect(double Width, double Height)
{
    public double Area => Width * Height;
}

// main.cs
var r = new Rect(3, 4.5);
Console.WriteLine($"Area: {r.Area}");
  • Only one file may have top-level statements. A second one stops the build with CS8802: Only one compilation unit can have top-level statements.
  • Two classes with a static Main give CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. The build has no /main option, so keep one Main.
  • A static Main in a class next to top-level statements gives warning CS7022, and the top-level statements run.
  • Run builds the same program whichever tab is open.

What isn’t available

  • NuGet packages. Only the .NET 10 libraries are referenced, so Newtonsoft.Json’s JsonConvert stops with CS0246. System.Text.Json is part of .NET and does the same job.
  • Windows Forms and WPF: using System.Windows.Forms; gives CS0234: The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?).
  • ASP.NET Core and web servers: the Microsoft.AspNetCore libraries aren’t referenced, and runs have no network.
  • unsafe code and pointers: the build doesn’t pass /unsafe, so an unsafe block gives CS0227: Unsafe code may only appear if compiling with /unsafe.

Errors you’re likely to see

  • “CS1002: ; expected”: a statement is missing its semicolon.
  • “CS0103: The name 'total' does not exist in the current context”: a misspelled name, or a variable declared inside a block and used after it.
  • “CS0029: Cannot implicitly convert type 'string' to 'int'”: int n = Console.ReadLine(); needs int.Parse() around the ReadLine().
  • “CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)”: cast with (int), or keep the value as a double.
  • “CS0165: Use of unassigned local variable 'sum'”: give the variable a value, such as int sum = 0;, before reading it.
  • “Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.”: a member was used on null, such as a list that was declared but never created with new.

csc names the place as main.cs(4,13), line 4 and column 13; Ctrl+Alt+G jumps to the line. After a failed run, Fix with AI explains the error and proposes a change you review before it applies.

Recent C# you can use

  • C# 12 collection expressions: int[] a = [1, 2, 3]; and List<string> names = [];.
  • C# 12 primary constructors on classes: class Account(decimal balance) { ... }.
  • C# 13 params collections: params ReadOnlySpan<int> as well as params int[].
  • C# 14 adds the field keyword in property accessors, extension members declared in extension blocks, and null-conditional assignment such as customer?.Name = "Ada";.
  • Records, switch expressions and pattern matching (C# 9 and earlier) all work too.

Questions

Which .NET and C# version is it?

C# 14 on .NET 10, compiled with Roslyn’s csc.

Do I need class Program and static void Main?

No. Top-level statements in main.cs are the program. A classic class with static void Main works too, as long as no file has top-level statements.

Can I use NuGet packages?

No. The build references only the .NET libraries, so packages such as Newtonsoft.Json aren’t there; System.Text.Json is.

Why does Console.Read() return 53 when I type 5?

Read() returns the character code, and '5' is 53. Read the line with Console.ReadLine() and convert it with int.Parse().

How do I read several numbers on one line?

Split the line and parse each part: Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(s => int.Parse(s)).ToArray().

Do I need using System.Linq?

No. System, System.Linq, System.Collections.Generic, System.IO, System.Net.Http and the threading namespaces are imported for every file. Others, such as System.Text, still need a using line.