C# is a modern, object-oriented programming language developed by Microsoft as part of its .NET initiative, first released in 2000 and currently at version 14 (2026, .NET 10). It combines type safety and garbage collection with fine-grained control when needed, running on the Common Language Runtime (CLR) which provides cross-platform support. The language has evolved significantly with features like async/await, LINQ, pattern matching, nullable reference types, and now extension members that prioritize developer productivity and code safety. Think of C# as a strongly-typed, garbage-collected language where you rarely manage memory manually but gain full low-level control via unsafe contexts, Span<T>, and stackalloc โ understanding this balance between safety and performance is key to mastering the language.
What This Cheat Sheet Covers
This topic spans 28 focused tables and 316 indexed concepts, 242 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Value Types and Built-in Types
These are the primitive building blocks you reach for first โ the integers, floating-point numbers, characters, and booleans that map to fixed amounts of memory. The trick is picking the right one: int and double cover most cases, but decimal exists for money where rounding errors are unacceptable, and the size-specific types matter when range or precision is on the line.
| Type | Example | Description | |
|---|---|---|---|
int x = 42; | โข 32-bit signed integer โข range -2,147,483,648 to 2,147,483,647 โข most common integer type. | ||
long y = 9_223_372_036_854_775_807L; | โข 64-bit signed integer โข use L suffix for literalsโข for values exceeding int range. | ||
double pi = 3.14159; | โข 64-bit floating-point โข default for decimal literals โข ~15โ17 digits precision. | ||
float f = 3.14f; | โข 32-bit floating-point โข requires f suffixโข ~6โ9 digits precision. | ||
decimal price = 19.99m; | โข 128-bit high-precision โข requires m suffixโข 28โ29 digits precision โข ideal for financial calculations. | ||
bool isValid = true; | โข Boolean type; only true or falseโข no implicit conversion from integers. | ||
char c = 'A'; | โข Single 16-bit Unicode character โข use single quotes โข supports escape sequences like '\n'. | ||
string name = "Alice"; | โข Immutable sequence of Unicode characters โข reference type despite behaving like a value type. | ||
byte b = 255; | โข 8-bit unsigned integer, range 0โ255 โข commonly used for binary data and byte arrays. | ||
short s = 32_000; | โข 16-bit signed integer, range -32,768 to 32,767 โข less common; prefer int for general use. | ||
uint u = 4_000_000_000u;ulong ul = 100uL; | โข Unsigned 32-bit and 64-bit integers โข never negative โข use u / uL suffixes. | ||
nint p = 42; | โข Platform-native integer size (32-bit on 32-bit process, 64-bit on 64-bit process) โข aliases for IntPtr / UIntPtrโข C# 9 feature. | ||
var list = new List<int>(); | โข Implicitly-typed local variable โข type inferred at compile time โข not dynamic typing. | ||
dynamic d = 5;d = "text"; | โข Type resolved at runtime โข bypasses compile-time type checking โข use sparingly. |