Articles
Concepts and traps, explained with runnable evidence. If a claim below can be shown in six lines of code, it is.
Language core
-
Why is 7 / 2 = 3 in C#? Integer division explained
Both operands int β fraction discarded, toward zero. The three fixes, the negative-number rules, and when it is exactly what you want.
-
var vs explicit types β when each is right
var is compile-time inference, not dynamic typing. Where it helps, where it hides load-bearing information.
-
struct vs class β value vs reference semantics
Assignment copies a struct, aliases a class. The mutation test that makes it click, the gotcha it explains, and when to pick which.
-
== vs .Equals() β which one, when
They agree for primitives; they split on null handling and on what "equal" means. Case-insensitive compare done right.
-
string vs StringBuilder β immutability and the += trap
Why s.Replace() changes nothing, why += in a loop is O(nΒ²), and the three-piece rule: interpolate, Join, or StringBuilder.
-
const vs readonly vs static readonly β three kinds of "never changes"
Compile-time literal vs per-object vs per-class. Why
constcopies into call sites, and whyreadonlydoesn't freeze contents. -
ref vs out vs in β what each parameter mode does
out writes only, ref reads and writes, in reads without copying. The direction table plus the CS0165/CS1510/CS0177 rules.
-
abstract class vs interface β the real difference
Half-built family member with state vs pure promise any class can make. Why one base class but many interfaces.
On the roadmap
- const vs readonly vs static readonly
- ref vs out vs in β who moves which value
- abstract vs interface β "is-a" vs "can-do"