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

C# switch pattern matching shown as a decision tree branching on object types and property values.
C#

C# Switch Pattern Matching: Syntax and Use Cases

Learn the syntax and practical use cases of C# switch pattern matching, including type, property, and relational patterns for cleaner branching logic.

C# switchpattern matchingrelational patternsproperty patterns
Illustration of a C# switch expression mapping an input to a return value, with arrows indicating pattern matching branches.
C#

Returning Values from a C# Switch Expression

Learn how C# switch expressions produce values directly, with syntax, pattern matching examples, and practical guidance on choosing between a switch expression and a switch statement.

C# switch expressionsReturn valuesC# patternsSwitch expression
A clean illustration showing a single input branching into multiple labeled output paths, representing the C# switch expression's pattern-based mapping.
C#

C# Switch Expression: Syntax and Practical Usage

Learn how the C# switch expression provides concise, pattern-based branching. This article covers its syntax, patterns, when to prefer it over a switch statement, common pitfalls, and compatibility notes.

C#switch expressionpattern matchingC# 8
A visual comparison of C# if-else and switch branching constructs, showing a decision path and a switch-like selection.
C#

C# if vs switch: Choosing the Right Branching Construct

Understand when to use an if-else chain vs a switch statement in C#. Compare syntax, pattern matching, performance, and maintainability.

C#switch statementif-elsepattern matching
Illustration of a C# switch statement symbol surrounded by multiple branching paths, representing pattern matching and control flow decisions.
C#

C# Switch Statement: Syntax, Patterns, and Pitfalls

Learn the C# switch statement and switch expressions, pattern matching, common pitfalls, and when to prefer switch over if-else or dictionaries.

switch statementpattern matchingswitch expressionscontrol flow
Illustration of combining multiple conditions in a C# if statement with logical operators and parentheses.
C#

C# Multiple Conditions in If Statement: Combining and Simplifying

Learn how to combine multiple conditions in C# if statements using &&, ||, parentheses, and pattern matching. Includes precedence, short-circuiting, nullable bools, and readability tips.

C#if statementslogical operatorsshort-circuiting
A visual metaphor for nested if statements in C#, showing a branching tree with multiple decision points, cleanly structured and readable.
C#

C# Nested If Statement: Readability and Alternatives

c# nested if statement: Learn how to write and refactor C# nested if statements. Understand when nesting is acceptable, how guard clauses improve readability, and when...

C#Control FlowCode ReadabilityRefactoring
Diagram showing an if else if chain evaluating conditions in sequence in C#
C#

C# else if Statement: Syntax, Behavior, and Usage

Learn how the C# else if construct works: syntax, evaluation order, common mistakes, and when to prefer switch or pattern matching.

C#conditional logicif elseswitch
Illustration of a C# if else statement with two distinct paths, one leading to true and one to false, in a clean software engineering style.
C#

C# if else Statement: Syntax, Usage, and Common Mistakes

Learn C# if/else syntax, common patterns, operator precedence, short-circuiting, and mistakes to avoid when writing real-world conditional logic.

C# conditional logicif else statementC# programmingcontrol flow
Illustration of a decision branch in C# showing a boolean condition guiding code flow along two paths.
C#

C# If Statement: Syntax and Real-World Usage

Learn the C# if statement syntax, how to use else and else if branches, and how to avoid common pitfalls when writing conditionals in real projects.

C# basicsconditional logiccontrol flowcode branching