Skip to content

Evaluating Code

Will Fuqua edited this page Jun 14, 2026 · 1 revision

Evaluating Code

Type C# at the prompt and press Enter to run it. The result, if any, is printed.

> Console.WriteLine("Hello World")
Hello World

> DateTime.Now.AddDays(8)
[6/7/2021 5:13:00 PM]

Multiple lines

  • Shift+Enter inserts a newline without running.
  • Enter on an incomplete statement also inserts a newline, so you can keep typing.
> var x = 5;
  var y = 8;
  x * y
40

Semicolons

  • Expressions do not need a semicolon and print their result.
  • Statements (such as assignments) need a semicolon. If one is missing, a newline is added instead of running incomplete code. Type the semicolon to complete it.
> var now = DateTime.Now; // assignment statement, semicolon required

> DateTime.Now.AddDays(8) // expression, no semicolon needed
[6/7/2021 5:03:05 PM]

Detailed output

Press Ctrl+Enter to run code and print a detailed view of the result, with members, nested values, and stack traces.

> DateTime.Now // Enter shows a compact representation
[5/30/2021 5:13:00 PM]

> DateTime.Now // Ctrl+Enter shows a detailed representation
[5/30/2021 5:13:00 PM] {
  Date: [5/30/2021 12:00:00 AM],
  Day: 30,
  DayOfWeek: Sunday,
  DayOfYear: 150,
  ...
}

Built-in commands

  • help (or ?): show in-REPL help.
  • clear: clear the screen (same as Ctrl+L).
  • exit: end the session (same as Ctrl+D).

Running code without the interactive prompt

  • csharprepl --eval "1 + 1" runs code, prints the result, and exits.
  • csharprepl --eval-file script.csx runs a file, prints the result, and exits.
  • Pipe input through stdin to evaluate it as one batch. Add --streamPipedInput to evaluate it line by line instead.

See Configuring CSharpRepl for the full option list.

Clone this wiki locally