Learn Cheatsheet

C#

Core C# syntax and features at a glance.

Types & Variables
int x = 5; 32-bit integer
double d = 3.14; 64-bit floating point
bool b = true; Boolean value
string s = "hi"; Unicode text (reference type)
var v = 42; Type inferred by compiler
string? n = null; Nullable reference type
Control Flow
if (a) { } else { } Conditional branch
for (int i=0; i<n; i++) { } Classic for loop
foreach (var x in col) { } Iterate over any IEnumerable
while (cond) { } Loop while condition is true
cond ? a : b Ternary operator
Classes & OOP
class Foo { } Class declaration
public int Prop { get; set; } Auto-implemented property
class Dog : Animal { } Inheritance with colon
virtual / override Polymorphism
interface IFoo { void Bar(); } Interface contract
abstract class Base { } Cannot be instantiated directly
LINQ
.Where(x => x > 0) Filter elements
.Select(x => x * 2) Transform each element
.OrderBy(x => x.Name) Sort ascending
.FirstOrDefault(x => ...) First match or default value
.Any(x => x > 5) True if any element matches
.Sum() / .Count() / .Average() Aggregation functions
.GroupBy(x => x.Key) Group elements by key
Async & Null
async Task<T> MethodAsync() Async method signature
await someTask Await without blocking thread
x ?? defaultValue Null-coalescing: right side if null
obj?.Property Null-conditional: null if obj is null
x is null / is not null Preferred null check in modern C#