Lesson Weekend

We're finally ready to craft our first C# code. This lesson will explore a tool called a REPL that will allow us to run C# code directly in the command line. This is similar to how we ran JavaScript code using tools like JSFiddle and the browser console in our Intro course.

The REPL


The next few lessons will use a command line tool called a REPL. This stands for READ - EVALUATE - PRINT - LOOP. It works as follows:

  1. We type in a line of code and hit enter. The REPL reads this code.
  2. The REPL then evaluates the code, figuring out what it does.
  3. Next it prints the result of running this code.
  4. Finally, it loops back to step 1 so we can enter more code.

Since we've installed dotnet script, we have a C# REPL available right in the terminal!

Accessing the REPL

We can launch the REPL by opening our Terminal application (on a Mac machine) or our GitBash application (on Windows), entering the following text, then hitting Enter:

$ dotnet-script

Regardless of operating system, we should be met with the following:

>

We're now in the REPL!

Command Notation

Before we run code, notice the last line in the command line response above reads >. This is our command prompt. Unlike the standard terminal command prompt we learned in Intro, which looks like this:

Guest-User:Desktop epicodus_student $

...Notice the REPL precedes the command prompt with > instead of $, like this:

>

When our curriculum depicts commands meant to be run in the REPL, we'll precede them with > instead of $. When you see this, you are not required to type a >. You will only type the command listed after the >.

If you see a command preceded with a $, like you did in Intro, that means the command is meant for the standard terminal.

Exiting the REPL

We can exit at any point by pressing Ctrl + C.

Now that we understand the basics of the C# REPL, let's practice. In the next few lessons, we'll cover how to use strings, variables, numbers and methods with C#.

Terminology


  • REPL stands for Read-Evaluate-Print-Loop. A REPL is a command line tool that allows users to enter lines of code and see the result in the terminal when executed.

Overview


  • You may launch your REPL at any time by entering this command into the command line: $ dotnet-script.

  • Commands meant to run in the REPL are preceded with a > in our curriculum. Commands meant to run in the standard command line are still preceded with $.

  • Once open, you can exit the REPL with the Ctrl + C command.

Lesson 1 of 5
Last updated more than 3 months ago.