-
Notifications
You must be signed in to change notification settings - Fork 123
Evaluating Code
Will Fuqua edited this page Jun 14, 2026
·
1 revision
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]- 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- 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]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,
...
}-
help(or?): show in-REPL help. -
clear: clear the screen (same as Ctrl+L). -
exit: end the session (same as Ctrl+D).
-
csharprepl --eval "1 + 1"runs code, prints the result, and exits. -
csharprepl --eval-file script.csxruns a file, prints the result, and exits. - Pipe input through stdin to evaluate it as one batch. Add
--streamPipedInputto evaluate it line by line instead.
See Configuring CSharpRepl for the full option list.