Quick Reference

Purpose: Fast lookup for syntax and common patterns while coding

Tip: Bookmark this page! You'll reference it constantly.


C# Syntax Quick Reference

Variables & Data Types

// Integer types
byte age = 25;              // 0 to 255
short year = 2024;          // -32,768 to 32,767
int count = 1000;           // -2 billion to 2 billion
long bigNum = 1000000L;     // Very large numbers

// Floating point
float price = 19.99f;       // 7 digits precision
double pi = 3.14159;        // 15-16 digits precision
decimal money = 99.99m;     // 28-29 digits (for money!)

// Other types
bool isActive = true;       // true or false
char letter = 'A';          // Single character
string name = "John";       // Text

// Nullable types
int? nullableInt = null;    // Can be null
string? nullableString = null; // C# 8.0+

// Type inference
var number = 42;            // Compiler figures out type
var text = "Hello";         // Still strongly typed!

String Operations

Operators

Control Flow

Arrays

Collections

Methods

Classes

Inheritance

Interfaces

Exception Handling


LINQ Quick Reference

Basic LINQ Syntax

Chaining LINQ Operations


Async/Await Patterns


File I/O Quick Reference


JSON Serialization (System.Text.Json)


Common Patterns Cheat Sheet

Null Checking

Collection Initialization

String Formatting

Loops vs LINQ

Value vs Reference Types


Time Complexity Reference

Operation
List
Dictionary
HashSet
Array
LinkedList

Add

O(1)*

O(1)*

O(1)*

N/A

O(1)

Insert

O(n)

N/A

N/A

N/A

O(1)**

Remove

O(n)

O(1)*

O(1)*

N/A

O(1)**

Search

O(n)

O(1)*

O(1)*

O(n)

O(n)

Access by index

O(1)

N/A

N/A

O(1)

O(n)

* Amortized, ** If you have the node


Error Messages Decoder

Common Compiler Errors:

"CS0103: The name '...' does not exist"

  • Variable/method not declared

  • Check spelling and scope

"CS1002: ; expected"

  • Missing semicolon

  • Check previous line

"CS0029: Cannot implicitly convert type"

  • Type mismatch

  • Use explicit cast or conversion

"CS0161: Not all code paths return a value"

  • Method missing return statement

  • Add return or throw exception

"CS1061: Type does not contain a definition for '...'"

  • Method/property doesn't exist

  • Check object type and spelling

Common Runtime Errors:

NullReferenceException

  • Accessing null object

  • Use null checks (?. or ??)

IndexOutOfRangeException

  • Array/list index too large

  • Check bounds

DivideByZeroException

  • Dividing by zero

  • Check divisor before dividing

InvalidOperationException

  • Operation not valid for current state

  • Check preconditions

ArgumentException

  • Invalid argument passed

  • Validate inputs


Keyboard Shortcuts Reference

Visual Studio:

Action
Shortcut

Run

F5

Run without debugging

Ctrl+F5

Build

Ctrl+Shift+B

Format document

Ctrl+K, Ctrl+D

Comment/Uncomment

Ctrl+K, Ctrl+C / Ctrl+K, Ctrl+U

Find

Ctrl+F

Replace

Ctrl+H

Go to definition

F12

IntelliSense

Ctrl+Space

Quick actions

Ctrl+.

VS Code:

Action
Shortcut

Run

F5

Open terminal

Ctrl+`

Format document

Shift+Alt+F

Comment/Uncomment

Ctrl+/

Find

Ctrl+F

Replace

Ctrl+H

Go to definition

F12

IntelliSense

Ctrl+Space

Command palette

Ctrl+Shift+P


When to Use What?

Collections:

  • List: Default choice, need order and index access

  • Dictionary<TKey, TValue>: Fast lookups by key

  • HashSet: Unique values, fast membership check

  • Queue: FIFO processing

  • Stack: LIFO processing, undo functionality

  • LinkedList: Frequent insertions/deletions in middle

Loops:

  • for: Known number of iterations, need index

  • foreach: Iterate over collection

  • while: Unknown iterations, condition-based

  • do-while: Must execute at least once

String Operations:

  • Concatenation (+): Few strings, simple cases

  • String interpolation ($""): Embed variables (preferred)

  • StringBuilder: Many concatenations in loop

  • string.Format(): Legacy code (use interpolation instead)


Naming Conventions


This reference contains everything you'll use daily. Keep it handy while coding!

Pro Tip: As you learn new concepts, add your own notes to this reference.

Next: Start coding and refer back here whenever you forget syntax!

Last updated