Browse by Topic

Popular

Latest

Latest C# Posts

Diagram showing a ReadOnlySpan pointing to a slice of a character array without copying.
C#

Using ReadOnlySpan in C# for Slicing and Validation

ReadOnlySpan in C# enables allocation-free slicing and validation of strings and buffers. Includes practical parsing examples, ref struct restrictions, and performance trade-offs.

ReadOnlySpanMemory ManagementSpan<T>High-Performance C#
Diagram comparing a C# array and a Span<T> view over the same memory block, highlighting zero-copy slicing.
C#

C# Span vs Array: Choosing the Right Type

Learn the practical differences between Span<T> and arrays in C#, including memory allocation, performance, and when to use each type.

Span<T>ArrayMemory ManagementC# Performance
Visual comparison of C# string and Span<T> showing a string as a contiguous block and a span as a view into that block.
C#

C# Span vs String: When to Use Each for Performance

Compare Span<T> and string in C# for memory efficiency and performance. Learn when to use each, how they differ, and see practical examples.

Span<T>stringmemory allocationperformance
Illustration of C# scoped ref limiting a reference lifetime within a method boundary.
C#

C# scoped ref: Controlling Reference Lifetimes

C# scoped ref: Learn how the scoped modifier in C# restricts reference lifetimes, prevents unsafe escapes, and improves safety with ref structs like Span<T>.

C#ref structscoped modifierSpan
Diagram comparing C# in, ref, and out parameter modifiers with arrows showing data flow.
C#

C# in vs ref vs out: Parameter Passing Explained

Learn how C# in, ref, and out parameter modifiers differ, when to use each, and how they affect method signatures and runtime behavior.

C#parameter modifiersrefout
Illustration of a readonly reference pointing to a struct in memory, with a lock icon indicating read-only access
C#

Understanding `readonly ref` in C#

c# readonly ref: Learn how `readonly ref` in C# enables returning and passing large structs by reference without mutation, reducing copies and improving performance.

C#ref returnsreadonly structsperformance
Diagram showing a large struct passed by readonly reference to avoid copying, with a lock icon indicating immutability.
C#

C# ref readonly: Passing Large Structs Without Copies

Learn how C# ref readonly and in let you pass or return large structs by reference without copying while preventing the callee from modifying them. See syntax, performance trade-offs, and common pitfalls.

ref readonlyC# performancereadonly structparameter passing
Diagram showing two arrows pointing to the same memory location, representing the C# ref keyword passing a variable by reference
C#

c# ref Keyword: Passing Arguments by Reference

Learn how the c# ref keyword passes arguments by reference, how it differs from out and in, and when to use it for mutation or performance.

C#ref keywordmethod parametersvalue types
Diagram showing a C# record object being copied via a with expression, highlighting the copied fields.
C#

C# Record with Object Copy: Using `with`

c# record with object copy: Learn how to copy C# record objects using `with` expressions, understand shallow vs deep copy behavior, and know when to use them.

C#RecordsObject CopyWith Expressions
Diagram showing two objects sharing references versus independent copies in C#
C#

C# Object Copying: Shallow vs Deep Copy

Learn how to copy objects in C# correctly. Compare shallow and deep copy approaches, understand reference semantics, and choose the right strategy.

C#Object CopyingDeep CopyShallow Copy