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

Illustration of C# AttributeUsage controlling where custom attributes can be applied, with targets like classes and methods shown as bounded regions.
C#

C# AttributeUsage: Controlling Custom Attribute Application

Learn how to use AttributeUsage in C# to define valid targets, allow multiple instances, and control inheritance for custom attributes.

C# AttributesAttributeUsageCustom AttributesReflection
Diagram showing a C# method with params keyword accepting multiple arguments into an array or collection icon.
C#

C# Params Collection: Syntax, Behavior, and Pitfalls

Learn how C# params handles variable arguments with arrays and the C# 13 params collections feature, including syntax, performance tradeoffs, and common mistakes.

C# paramsvariable argumentsIEnumerablearrays
Editorial diagram of collection elements spreading into a combined C# collection expression
C#

C# Collection Expression Spread Element: Syntax and Behavior

Use the `..` spread element in C# collection expressions to copy elements from an existing collection into arrays, lists, spans, and immutable arrays. Includes syntax, runtime behavior, allocation tradeoffs, and edge cases.

C# 12collection expressionsspread elementarrays
Diagram showing a Span<T> referencing a segment of an array, with arrows indicating zero-copy slicing.
C#

C# Span Usage: Process Memory Slices Without Allocations

c# span usage: Learn how to use Span<T> in C# to slice arrays and strings, avoid allocations, and process memory efficiently in high-performance code.

Span<T>Memory<T>ref structperformance
A diagram showing IComparable and IComparer interfaces and their roles in sorting objects in C#.
C#

C# IComparable vs IComparer: When to Use Each

Understand the difference between IComparable and IComparer in C#, see how to implement both interfaces, and learn when each one fits sorting and comparison logic.

IComparableIComparerSortingC# Interfaces
Illustration of two C# objects being compared with an ordering arrow, representing the IComparable comparison contract
C#

Implementing IComparable in C# for Reliable Sorting

c# icomparable: Learn how to implement IComparable<T> in C# for custom sorting, including CompareTo semantics, null handling, and consistency with Equals.

C#IComparableCompareToSorting
A C# code snippet showing a class implementing IComparable<T> with a sorting arrow icon in the background.
C#

C# Comparable: Implementing IComparable for Sorting

Learn how to implement IComparable<T> in C# to sort custom objects with List.Sort and Array.Sort, including null handling and common edge cases.

IComparableC# SortingCompareToIComparer
Illustration comparing two C# objects with value equality versus reference equality, showing records and classes.
C#

C# Record Equality vs Class Equality Explained

C# records and classes differ in equality behavior. Learn how value semantics work, when reference equality still matters, and how to customize record equality.

C#RecordsEqualityIEquatable
Two overlapping object diagrams with a comparison symbol, illustrating reference equality versus value equality in C#.
C#

C# Reference Equality vs Value Equality

c# reference equality vs value equality: Understand the difference between reference equality and value equality in C#, how to implement custom equality, and when reco...

EqualityIEquatableRecordsStructs
Diagram showing two objects being compared by a custom C# equality comparer with hash and equality checks.
C#

C# Equality Comparer: Implementing IEqualityComparer<T>

Learn how to implement a C# equality comparer with IEqualityComparer<T> for LINQ and Dictionary, including GetHashCode rules and performance considerations.

IEqualityComparerLINQGetHashCodeDictionary