coderef

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.

  • Hello world (top-level)
  • Variables
  • Nullable
  • Read input
  • Convert
  • Null handling

Strings

Text.

  • Interpolation
  • Format a number
  • Common methods
  • Split / join
  • Raw string literal

Collections & LINQ

Lists, dictionaries and queries.

  • List
  • Dictionary
  • Array
  • Filter / map
  • Sort
  • Reverse
  • Aggregate
  • First / any
  • Group by

Control flow

Conditions and loops.

  • If / else
  • Switch expression
  • Loops
  • Pattern matching

Types

Classes, records and interfaces.

  • Class with properties
  • Primary constructor
  • Record
  • Interface
  • Inheritance
  • Enum

Async & errors

Tasks and exceptions.

  • Async method
  • Run in parallel
  • Try / catch
  • Files

dotnet CLI

Create and run projects.

  • New console app
  • Run / build / test
  • Add a package
  • Publish

← All quick references