Operating on variables
Operators apply simple operations such as addition and multiplication to operands such as numbers. They usually return a new value that is the result of the operation.
Most operators are binary, meaning that they work on two operands, as shown in the following pseudocode:
var resultOfOperation = FirstOperand operator SecondOperand;
Some operators are unary, meaning they work on a single operand.
A ternary operator works on three operands.
Experimenting with unary operators
Two common unary operators are used to increment ++
and decrement --
a number.
In Visual Studio 2017, from the View menu, choose Other Windows, and then C# Interactive.
Note
In Visual Studio Code, create a new console application and write your own statements to output the results using Console.WriteLine()
.
Enter the following code:
> int i = 3; > i 3
Note that when you enter a full statement ending in a semicolon, it is executed when you press Enter.
The first statement uses the assignment operator...