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

Diagram showing a record struct value being copied between two variables, illustrating value semantics.
C#

C# record struct: Value Semantics with Record Features

Record structs combine C# value-type semantics with record syntax. See how positional declarations, value equality, mutation, readonly variants, and performance tradeoffs work, and when to choose one over a record class or plain struct.

record structC# 10value typesvalue equality
Illustration of a C# ref struct as a stack-only value type with Span<T> referencing contiguous memory.
C#

C# ref struct: Constraints and Practical Use

Learn how C# ref struct types enforce stack-only allocation, what compiler restrictions they carry, and how Span<T> uses them for safe, allocation-free memory access.

ref structSpan<T>stackallocvalue types
Diagram showing a readonly struct preventing defensive copies in C#
C#

C# Readonly Struct: When and How to Use

c# readonly struct: Learn how C# readonly structs prevent defensive copies, enforce immutability, and when they improve performance.

C#structsimmutabilityvalue types
Diagram showing a C# struct value on the stack with a constructor assigning its fields, illustrating value-type initialization.
C#

C# Struct Constructor: Rules and C# 10 Changes

c# struct constructor: Learn C# struct constructor rules: parameterized constructors, implicit parameterless initialization, C# 10 field initializers, and performance.

C#structconstructorsvalue types
Diagram comparing a struct's value copy on assignment with a class's shared reference, illustrating C# value and reference type behavior.
C#

C# Struct vs Class: Choosing the Right Type

c# struct vs class: Understand the differences between C# structs and classes: value vs reference semantics, memory allocation, performance tradeoffs, and when to choo...

C#structclassvalue types
Diagram showing a C# struct declaration with value type semantics and memory allocation.
C#

C# Struct Declaration: Syntax, Semantics, and Performance

Learn how to declare and use C# structs, understand value type copying semantics, and decide when a struct is a better choice than a class.

structvalue typesC# syntaxmemory allocation
Diagram showing a small struct value copied between two boxes, contrasting with a reference pointing to a heap object.
C#

C# Struct Usage: Value Types and When to Use Them

c# struct usage: Understand C# struct usage: value type semantics, allocation behavior, performance tradeoffs, and when structs beat classes in real code.

C# structsvalue typesheap allocationreadonly struct
Editorial illustration showing a C# enum default value of zero with the zero member highlighted in a grid.
C#

C# Enum Default Value: What default(MyEnum) Returns

Learn what default(MyEnum) returns in C#, why an enum's default value is always 0, and how to handle enums without a zero member.

C#EnumsDefault Values.NET
A diagram showing an enum value flowing into a switch statement with multiple labeled branches and a default path.
C#

C# Enum Switch: Patterns and Pitfalls

Learn how to use C# switch statements and switch expressions with enums, including default handling, pattern matching, and maintainability tips.

C#enumswitch statementswitch expression
Illustration of a C# flags enum where binary bits are combined using bitwise operations.
C#

Using Flags Enums in C#

Learn how to design and use C# flags enums to combine multiple options with bitwise operations, including declaration, parsing, validation, and common pitfalls.

EnumsBitwise OperationsC#FlagsAttribute