C# Cheatsheet - C# Syntax & .NET Reference
This reference is for .NET developers building web APIs, services, or desktop apps, focusing on the C# syntax you write every day: classes and interfaces with their access modifiers, LINQ for querying collections instead of hand-written loops, async/await for I/O-bound work, generics and delegates, and the property/event model. Unlike a flat C# feature list, entries are grouped by the language construct and note where C# behavior differs from Java or JS. After reading you should be able to replace a nested loop with a composed LINQ query, set up an async method without deadlocking, and design a type with properties, events and a delegate.
Classes & Interfaces 7
public class MyClass { }public interface IMyInterface { void Method(); }public class Derived : Base, IMyInterface { }public abstract class AbstractClass { }public sealed class SealedClass { }public static class Utils { }public record Person(string Name, int Age);Properties & Methods 6
public int Age { get; set; }public string Name { get; init; }public int Age => _age;public void Method() { }public int Add(int a, int b) => a + b;public event EventHandler MyEvent;LINQ Queries 8
var result = list.Where(x => x > 5);var result = list.Select(x => x * 2);var result = list.OrderBy(x => x.Age);var result = list.GroupBy(x => x.Category);var result = list.First(x => x.Id == 1);var result = list.Any(x => x > 0);var result = list.Sum(x => x.Price);var result = list.Aggregate((a, b) => a + b);Asynchronous 6
public async Task<int> GetDataAsync() { }await Task.Delay(1000);var result = await httpClient.GetStringAsync(url);Task.Run(() => { });await Task.WhenAll(task1, task2);CancellationTokenSource cts = new();Generics & Delegates 6
public class Stack<T> { }public T Max<T>(T a, T b) where T : IComparable<T> { }public delegate void MyDelegate(string msg);public event Action<string> OnMessage;public Func<int, int, int> add = (a, b) => a + b;public Predicate<int> isPositive = x => x > 0;Collections & Dictionaries 6
List<int> list = new() { 1, 2, 3 };Dictionary<string, int> dict = new();HashSet<int> set = new() { 1, 2, 3 };Queue<int> queue = new();Stack<int> stack = new();var tuple = (1, "hello");Tips
- LINQ queries are lazily evaluated; they run only when the results are enumerated.
- async/await is core to asynchronous programming; avoid blocking the UI thread.
- C# 9 introduced record types, ideal for immutable data models.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us