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# HashSet showing unique elements and fast lookup operations.
C#

C# HashSet Usage: Efficient Set Operations

Learn how to use C# HashSet for fast membership checks, deduplication, and set operations, with practical examples and performance tradeoffs.

C#HashSetSet OperationsPerformance
A visual comparison of a C# Dictionary and List, showing key-based lookup versus index-based access with a performance scale.
C#

C# Dictionary vs List: Choosing the Right Collection

Compare C# Dictionary and List collections by lookup, iteration, memory, and typical access patterns to decide when to use each.

DictionaryListC# CollectionsPerformance
Illustration of a C# dictionary lookup returning a default value when a key is missing, with emphasis on safe retrieval.
C#

C# Dictionary GetValueOrDefault: Usage and Behavior

Learn how Dictionary.GetValueOrDefault works in C#: default return values for missing keys, the overload with an explicit fallback, comparison with TryGetValue, and common edge cases.

C#Dictionary.NETCollections
A C# Dictionary with a key that appears twice, showing a decision between throwing an exception, overwriting, or skipping.
C#

C# Dictionary Duplicate Key Handling

Dictionary.Add throws when a key already exists, while the indexer overwrites. See how to choose among Add, TryAdd, indexer updates, custom comparers, and ConcurrentDictionary.

C#DictionaryDuplicate KeysTryAdd
A C# code editor showing a foreach loop iterating over a dictionary's key-value pairs.
C#

C# Dictionary Key-Value Iteration: Methods and Pitfalls

Understand C# Dictionary key-value iteration with foreach, LINQ, and safe modification patterns, including ordering and performance considerations.

DictionaryIterationKeyValuePairLINQ
Illustration of a hand holding a key while a loop arrow passes over a dictionary, representing C# Dictionary foreach iteration.
C#

C# Dictionary foreach: Iteration Patterns and Pitfalls

Learn how C# Dictionary foreach works: iterate key-value pairs, keys, or values, and avoid common pitfalls such as modifying a dictionary during enumeration.

C#DictionaryforeachKeyValuePair
Illustration of clearing a C# Dictionary showing the Clear method and memory release.
C#

C# Dictionary Clear: Syntax, Behavior, and Performance

Learn how to clear a C# Dictionary with the Clear() method, understand what happens to memory and capacity, and compare Clear() with reassigning a new dictionary.

DictionaryC#.NETMemory Management
Editorial illustration of a C# dictionary key-value card being removed from a stack, representing the Dictionary Remove method.
C#

Removing Entries from a C# Dictionary

A practical guide to C# Dictionary removal: Remove overloads, missing-key return values, enumeration pitfalls, and ConcurrentDictionary.TryRemove.

C#Dictionary.NETConcurrentDictionary
Illustration of a C# dictionary with a magnifying glass scanning values, representing ContainsValue lookup
C#

C# Dictionary ContainsValue: Usage and Performance

c# dictionary containsvalue: Learn how Dictionary.ContainsValue works, its O(n) complexity, equality rules, and when to use it instead of ContainsKey or alternative st...

DictionaryContainsValueC# CollectionsPerformance
C# Dictionary ContainsKey method checking for a key in a hash table
C#

Using C# Dictionary ContainsKey Effectively

Learn how to use C# Dictionary.ContainsKey for safe key lookups, avoid double lookups, and compare its performance tradeoffs with TryGetValue in common dictionary patterns.

DictionaryContainsKeyC# CollectionsKey Lookup