30
loading...
This website collects cookies to deliver better user experience
At the end of this lesson, you should be able to answer the following:
10 + 2
+
symbol between the two numbers is an operator. It represents an action or operation that can be done to the values supplied with it. The +
operator here is the same used in arithmetic addition.Why did it display the result even if we didn't call Console.WriteLine()
?
Dotnet Interactive is also a REPL - an environment that allows quick evaluation of an expression, after which the output is displayed.
If we write more than one statement in the code box, it won't be a single expression anymore and instead of doing the read-evaluate-print loop, Dotnet Interactive will compile the program as a whole.
10 - 2 // subtraction
10 * 2 // multiplication
10 / 2 // division
10 + 2;
10 - 2;
10 * 2;
10 / 2;
Console.WriteLine()
call.Console.WriteLine(10 + 2);
Console.WriteLine(10 - 2);
Console.WriteLine(10 * 2);
Console.WriteLine(10 / 2);
Operator | Description | Example |
---|---|---|
+ |
Addition | 17 + 18 |
- |
Subtraction | 65 - 21 |
* |
Multiplication | 12 * 4 |
/ |
Division | 60 / 15 |
% |
Remainder (modulo) | 20 % 3 |
true
or false
.Operator | Description | Example |
---|---|---|
> |
Greater than | 5 > 2 |
< |
Less than | 1 < 7 |
>= |
Greater than or equal to | 9 >= 6 |
<= |
Less than or equal to | 1000 < 84 |
== |
Equal to | "apple" == "orange" |
!= |
Not equal to | "apple" != "orange" |
Operator | Description | Example |
---|---|---|
&& |
Logical AND | true && false |
|| | Logical OR |
false || true
|
! |
Logical NOT | !false |
Question
Is the following an expression? Why or why not?
"100 + 25"
Question
True or False: An expression by itself is a valid statement.
Challenge
Wrap each example in the tables above into a Console.WriteLine()
statement. Can you guess what each result will be?