Pages

Topics

Tools

↑↓navigate↵openescclose

C# guides

Every published C# guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest C# guides

A technical illustration showing two paths for C# parameter passing: one where the caller initializes a value before the method modifies it, and one where the method produces a new value for the caller.
C#

C# ref vs out: Choosing the Right Parameter Modifier

Understand the practical difference between C# ref and out parameters: initialization rules, compiler enforcement, and when to use each modifier.

C#ref parameterout parametermethod parameters
Illustration of a StringBuilder buffer with appended segments, showing how text is added without creating new strings.
C#

Using StringBuilder.Append in C# Without Wasteful Allocations

Learn how to use StringBuilder.Append efficiently in C# to build strings without repeated allocations, with practical examples and performance tradeoffs.

StringBuilderString ConcatenationPerformance.NET
Comparison of C# string and StringBuilder showing immutability and mutable buffer.
C#

C# String vs StringBuilder: When to Use Each

Learn when to use C# string versus StringBuilder, how immutability affects performance and memory, and how to choose the right approach.

C#.NETStringBuilderString Concatenation
Diagram comparing string concatenation and StringBuilder memory allocation in C#.
C#

C# StringBuilder: When and How to Use It

Learn how to use C# StringBuilder effectively, including when it improves performance, common methods, and thread-safety considerations.

StringBuilderC# PerformanceString ConcatenationMemory Allocation
Illustration of a C# string being split into individual characters arranged in an array.
C#

C# String to Char Array: Using ToCharArray

c# string to char array: Convert a C# string to a char array with ToCharArray, handle edge cases, and understand when an array is the right choice.

C#StringChar ArrayToCharArray
Illustration of C# string replace operation showing substring substitution
C#

C# String Replace: Syntax, Overloads, and Performance

Learn how to use C# string.Replace, including string and character overloads, all-occurrence behavior, case sensitivity, performance tradeoffs, and when to choose Regex or StringBuilder.

string manipulationC# methodsRegexStringBuilder
Illustration of a C# foreach loop iterating over a collection with a cursor moving through elements sequentially.
C#

C# foreach Loop: Syntax, Behavior, and Performance

c# foreach loop: Learn how to use the C# foreach loop to iterate over collections, understand its runtime behavior, avoid common pitfalls, and know when to choose it o...

C#foreachIEnumerableCollections
Illustration of a C# switch statement with a default case highlighted, representing fallback behavior.
C#

C# Switch Default: When No Case Matches

Understand when the C# switch default case runs, how to use it in switch statements and switch expressions, and how to avoid common pitfalls.

C# switchdefault casepattern matchingswitch expression
A diagram showing a C# switch case branching into multiple outcomes with pattern matching and a a default path.
C#

C# Switch Case: Syntax, Patterns, and Pitfalls

Learn C# switch case syntax, switch expressions, pattern matching, common mistakes, and performance considerations for clean control flow.

switch statementpattern matchingswitch expressionsC# control flow
A visual representation of the C# null coalescing assignment operator assigning a value only when the left operand is null.
C#

C# Null Coalescing Assignment Operator

c# null coalescing assignment operator: Learn how to use the C# null coalescing assignment operator (??=) to assign values only when a variable is null, with practical...

C#Null CoalescingNull HandlingAssignment