Constants
Constants are like variables except you can define their value only once. So technically, not variables.
Constants and variables…
— Elizabeth Comstock, Bioshock Infinite
To define a constant:
const <type> name = value;
Like:
const double pi = 3.1416;
Operators
Eh, operators.
Arithmetic Operators
+, -. *, /, … ah I already know them!
Relational Operators
==, !=. >, <, >=, etc.
Logical Operators
| Operator | Description |
|---|---|
| && | AND |
| ` | |
| !(condition) | NOT |
Bitwise Operators
| Operator | Name | Description |
|---|---|---|
| & | AND | Copies a bit from both operands. |
| ` | ` | OR |
| ^ | XOR | Copies a bit exclusively from either operands. |
| ~ | Complement Operator | Reverses bits (0 becomes 1 and vice versa). Good for converting negative numbers. |
| << | Left Shift | Pushes bits to the left by a number of bits. |
| >> | Right Shift | Pushes bits to the right by a number of bits. |
Decision Making
if, if else, else if. if else can be replaced by ternary operator like so:
string str = (a >= b) ? "Good." : "Bad.";
Console.Write(str);
else if, you would realize that it looks like a parallel circuit in electronics.Switch decision making
int num = value;
switch(num)
{
case 1:
code;
break;
case 2:
code;
break;
case 3:
code;
break;
default:
code;
break;
}