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

Editorial illustration of a dictionary key lookup using TryGetValue, showing a single arrow connecting a key to its stored value
C#

Using C# Dictionary TryGetValue for Safe Lookups

Learn how Dictionary.TryGetValue performs a single lookup for key existence and value retrieval, when it beats ContainsKey plus the indexer, and how it handles null values.

DictionaryTryGetValueC# CollectionsConcurrency
Illustration of a C# dictionary lookup showing key-value pairs and the indexer, TryGetValue, and ContainsKey retrieval paths.
C#

C# Dictionary Get Value: Safe Lookup Patterns

Retrieve values from a C# Dictionary with the indexer, TryGetValue, or ContainsKey, and learn about null handling, custom comparers, and concurrency.

DictionaryTryGetValueC# CollectionsLookup Performance
Illustration of updating a key-value pair in a C# Dictionary with indexer and TryGetValue approaches.
C#

C# Dictionary Update Value: Indexer vs TryGetValue

Learn how to update values in a C# Dictionary using the indexer and TryGetValue. Compare behavior for existing and missing keys, avoid common pitfalls, and use ConcurrentDictionary for thread-safe updates.

C#Dictionary.NETCollections
Illustration of a C# dictionary with a key-value pair being inserted, highlighting the Add operation and duplicate key handling.
C#

C# Dictionary Add: Syntax, Exceptions, and Performance

Learn how to add entries to a C# Dictionary with Add, the indexer, and TryAdd. See how duplicate keys behave, when exceptions occur, and how to choose the right insertion approach.

C#DictionaryCollectionsException Handling
A visual metaphor for C# dictionary initialization showing key-value pairs being inserted into a structured map.
C#

C# Dictionary Initialization: Syntax and Tradeoffs

Learn the main ways to initialize a Dictionary in C#: collection initializers, constructors, Add methods, and LINQ, with performance tradeoffs and common pitfalls.

C#DictionaryCollection InitializerC# Syntax
Diagram showing a C# dictionary declaration mapping string keys to integer values with a clean arrow between key and value boxes.
C#

C# Dictionary Declaration: Syntax and Initialization

Learn how to write a C# dictionary declaration with type parameters, collection initializers, initial capacity, custom comparers, and performance tradeoffs.

DictionaryC# CollectionsCollection InitializerGeneric Types
A visual representation of a C# dictionary mapping keys to values, with a magnifying glass indicating fast lookup.
C#

C# Dictionary Usage: Key Operations and Performance

Learn practical C# Dictionary operations: fast key-value lookups, missing-key handling, performance considerations, and thread-safe alternatives.

C# DictionaryCollectionsPerformanceThread Safety
Illustration of a C# list with duplicate items being filtered into a unique list using a HashSet and LINQ, showing order preservation.
C#

Remove Duplicates from a List in C#

Learn how to remove duplicates from a List<T> in C# using LINQ Distinct, HashSet, and custom comparers, with performance tradeoffs, order preservation, and in-place removal.

C#LINQList<T>HashSet
Illustration of an array being converted to a list in C# with arrows and brackets.
C#

C# Array to List: Conversion Methods and Performance

Learn how to convert a C# array to a List with ToList() or the List<T> constructor, including performance, memory, and common pitfalls.

C#ArraysListsLINQ
Diagram showing a C# List<T> being converted to an array with ToArray(), illustrating the element copy process.
C#

C# List to Array: Converting Collections with ToArray()

Convert a List<T> to an array in C# with ToArray() or CopyTo(), and understand the type, performance, and memory implications of each approach.

C#.NETList<T>Arrays