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 a magnifying glass inspecting items in a C# list collection, with one item highlighted to represent a match found by the Contains method.
C#

C# List Contains: Checking for Elements in a List

Learn how List<T>.Contains works in C#, how equality is determined for value and reference types, and when HashSet is more efficient for membership checks.

List<T>ContainsEqualityHashSet
Illustration of a C# List being cleared, showing an empty container after the Clear method is called.
C#

C# List Clear: How to Empty a List in C#

c# list clear: Learn how to use List<T>.Clear() to remove all elements from a C# list, including performance implications, alternatives, and common pitfalls.

List<T>Clear methodC# collectionsmemory management
Illustration of a C# List being filtered by a predicate using RemoveAll.
C#

Using List.RemoveAll in C# to Filter Elements

Learn how to use List<T>.RemoveAll in C# with predicates, including runtime behavior, performance tradeoffs, and alternatives.

C#List<T>RemoveAllPredicate
Illustration of a C# List with an element being removed at a specific index, showing the shifting of subsequent elements.
C#

C# List RemoveAt: Removing Elements by Index

Learn how List<T>.RemoveAt works in C#, including its performance characteristics, common pitfalls, and when to use alternatives.

C#List<T>RemoveAtCollections
Illustration of removing an element from a C# List, showing the remaining elements shifting left to fill the gap.
C#

C# List Remove: Methods and Performance

Remove elements from a C# List<T> using Remove, RemoveAt, RemoveAll, and RemoveRange, with examples, performance tradeoffs, and common pitfalls.

C#List<T>RemoveRemoveAll
Illustration of inserting an element into a C# list at a specific index, showing the shifting of subsequent elements.
C#

C# List Insert: Syntax, Behavior, and Performance

Learn how to use List<T>.Insert in C# to add elements at a specific index, understand its O(n) shifting behavior, and know when to choose alternatives.

C#List<T>InsertCollection
A diagram showing elements from a source collection being appended to a C# List<T> via AddRange, with the internal array growing to accommodate the new elements.
C#

C# List AddRange: Syntax, Behavior, and Performance

Learn how C# List<T>.AddRange appends IEnumerable<T> sources, handles capacity and deferred LINQ queries, and when it is a better choice than repeated Add calls.

C#List<T>Collections.NET
Illustration of a C# List being appended with an element, showing dynamic array growth and capacity expansion.
C#

C# List Add: How to Add Elements to a List

Learn how to add elements to a C# List<T> with the Add method, understand capacity resizing, and avoid common pitfalls.

C#List<T>Add methodsub_keywords
Illustration of C# list initialization showing different syntax patterns and a list icon.
C#

C# List Initialization: Syntax, Examples, and Performance

c# list initialization: Learn C# list initialization with collection initializers, LINQ, and performance considerations for efficient code in your applications.

C#List<T>Collection InitializersLINQ
Illustration of a C# List declaration with curly braces and type parameters
C#

C# List Declaration: Syntax and Initialization

Learn how to declare and initialize List<T> in C#, including empty lists, collection initializers, initial capacity, var inference, and common declaration mistakes.

List<T>C# CollectionsInitializationType Inference