"Foo" // string
'F' // Char
Console.WriteLine("c:\source\repos\foo"); // c:sourcereposfoo ⚠️
Console.WriteLine("c:\\source\\repos\\foo"); // c:\source\repos\foo
Console.WriteLine(@"c:\source\repos\foo"); // c:\source\repos\foo
string name = "foo";
string path = $"C:\\source\\repos\\{name}";
Console.WriteLine(path); // c:\source\repos\foo
Console.WriteLine($@"C:\source\repos\{name}"); // c:\source\repos\foo
int qty = 7;
Console.WriteLine("Total: " + qty + 7 + " items");
// └─ Convertions before concatenation
// Total: 77 items
int qty = 7;
Console.WriteLine("Total: " + (qty + 7) + " items");
// └─ Use parentesis to change the order
// Total: 14 items
int sum = 7 + 5; // 12
int difference = 7 - 5; // 2
int product = 7 * 5; // 35
int quotient = 7 / 5; // 1 ⚠️
int modulus = 7 % 5; // 4
int quotient = 7 / 5; // 1
// └───┴── Both Integers, result is Integer
decimal quotient = 7m / 5; // 1.4
decimal quotient = 7 / 5.0m; // 1.4
// └────┴── For fractional results,
// pass one value as a Decimal
decimal quotient = 7.0 / 5;
// └─ This will fail!
// error CS0266:
// Cannot implicitly convert type 'double' to 'decimal'.
// An explicit conversion exists (are you missing a cast?)
int first = 7;
int second = 5;
decimal quotient = (decimal) first / second;
// └─ When using variables,
// just cast the needed type!
In math, PEMDAS
is an acronym remember the order operations are performed:
- Parentheses ── Whatever is inside performs first)
- Exponents ── ⚠️
- Multiplication ╮
- Division ├─ From left to right
- Addition │
- Subtraction ╯
⚠️ There's no exponent operator in C#, useSystem.Math.Pow()
instead