Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
We'll learn another tool called the Mono C# REPL.
To compile:
mcs Program.cs
To run:
mono Program.exe
-
0:00
[MUSIC]
-
0:04
[SOUND] Before we go on,
-
0:05
I want to introduce you to another tool we have available to us in the console.
-
0:09
So far, we've used the mono C# compiler to compile our code.
-
0:14
The compiler turns our code, which may be contained in multiple files,
-
0:18
into a single file that can be run as a program.
-
0:21
It also converts the human readable C# code,
-
0:24
into code that the computer can more easily understand.
-
0:28
Our code must follow all the rules of the C# language.
-
0:32
Otherwise the compiler can't understand our code well enough to perform
-
0:35
this conversion.
-
0:37
This is why we occasionally get compiler errors.
-
0:40
Compilers convert code files into programs.
-
0:44
But what if we just wanna run a few lines of C# code without creating a file,
-
0:48
writing a class and a method?
-
0:50
Well, the Mono C# compiler comes with a tool for doing just that.
-
0:56
This type of program is called a REPL.
-
0:58
Just like MSC, it also runs right in the console.
-
1:02
REPL stands for Read, Evaluate, Print, Loop,
-
1:06
which describes what it does each time we give it a line of code to run.
-
1:10
First, it reads our code from the console.
-
1:13
Then is evaluates it, which means it runs it.
-
1:16
Then it prints something back to the console.
-
1:18
The final step, Loop, in coding terms, means to repeat.
-
1:23
So, it starts all over again and waits for us to enter another line of code.
-
1:27
I think it's best to show you how it works.
-
1:30
To launch the C# REPL, just go to the console in workspaces and type csharp.
-
1:37
Now we can write code like we would inside of a method.
-
1:40
For instance let's declare a variable and assign it a value.
-
1:45
Now we can see what the value of the truth variable contains just by typing it and
-
1:48
pressing Enter.
-
1:50
Just like at the command prompt on the console,
-
1:52
you can press the up arrow to see what you've previously run.
-
1:55
Let's run the code again.
-
1:57
Finally you can type quit when you want to exit the REPL.
-
2:02
For the rest of this course, I'll use the C# REPL, as a teaching tool to demonstrate
-
2:07
some of the features of the C# programming language.
-
2:10
We'll also continue to code up our Fitness Frog app.
-
2:14
If you've ever used a language like Ruby or Python,
-
2:16
then you've probably used a REPL program before.
-
2:20
Oddly enough, Most C# programmers don't use REPLs.
-
2:23
You wouldn't ever use a REPL to actually run a program.
-
2:27
i find it incredibly useful though because it's an excellent way to learn
-
2:31
a programming language through experimentation.
-
2:35
Without the REPL, I find myself making lots of small programs and
-
2:39
compiling them just so that I can experiment with some code.
You need to sign up for Treehouse in order to download course files.
Sign up