C# Quick Reference
C# essentials: variables, strings, collections, LINQ, classes, records, async/await, exceptions and the dotnet CLI.
7 sections · 38 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Programs and variables.
TaskCode
- Hello world (top-level)
- Variables
- Nullable
- Read input
- Convert
- Null handling
Strings
Text.
TaskCode
- Interpolation
- Format a number
- Common methods
- Split / join
- Raw string literal
Collections & LINQ
Lists, dictionaries and queries.
TaskCode
- List
- Dictionary
- Array
- Filter / map
- Sort
- Reverse
- Aggregate
- First / any
- Group by
Control flow
Conditions and loops.
TaskCode
- If / else
- Switch expression
- Loops
- Pattern matching
Types
Classes, records and interfaces.
TaskCode
- Class with properties
- Primary constructor
- Record
- Interface
- Inheritance
- Enum
Async & errors
Tasks and exceptions.
TaskCode
- Async method
- Run in parallel
- Try / catch
- Files
dotnet CLI
Create and run projects.
TaskCode
- New console app
- Run / build / test
- Add a package
- Publish