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 C# method signature with generic type parameters and constraints
C#

C# Generic In Parameter: Syntax and Constraints

c# generic in parameter: Learn how to define and use generic type parameters in C# methods, including constraints, multiple parameters, and runtime behavior.

C#GenericsType ParametersMethod Constraints
Diagram showing a C# generic method with an out parameter and the type inference constraint.
C#

C# Generic Out Parameter: Type Inference Explained

Generic methods with out parameters have type-inference constraints at the call site. This article explains why explicit type arguments are often required and compares TryGetValue and tuple alternatives.

C# genericsout parameterstype inferenceTryGetValue pattern
Diagram showing a contravariant generic interface where a general object comparer is assigned to a specific string comparer variable.
C#

C# Contravariance: How the in Keyword Works

Learn how C# contravariance works with delegates and generic interfaces, including the in keyword, practical usage, and common type-safety boundaries.

C# genericsvariancedelegatesgeneric interfaces
Diagram showing assignment of IEnumerable<string> to IEnumerable<object> with a checkmark for safe covariance.
C#

Understanding C# Covariance in Generics and Interfaces

c# covariance: Learn how C# covariance works in arrays, generic interfaces, and delegates, where it is allowed, and how to avoid runtime exceptions.

C# GenericsCovarianceContravarianceType Safety
Illustration of C# generic variance showing covariance and contravariance directions between base and derived types.
C#

C# Generic Variance: Covariance & Contravariance

c# generic variance: Understand C# generic variance: how out and in keywords enable covariance and contravariance in interfaces and delegates, with practical examples.

covariancecontravariancegeneric interfacesdelegates
Diagram showing a C# object with a finalizer and GC.SuppressFinalize preventing finalization.
C#

C# GC.SuppressFinalize: When and Why to Call It

Learn when and why to call GC.SuppressFinalize in C#, how it interacts with finalizers and IDisposable, and common pitfalls.

Garbage CollectionIDisposableFinalizersMemory Management
Comparison of IDisposable and finalizer cleanup paths in C# showing deterministic vs garbage-collected timing.
C#

C# Dispose vs Finalizer: When to Use Each

Understand the difference between IDisposable and finalizers in C#, when each runs, and how to implement the Dispose pattern correctly.

IDisposableGarbage CollectionResource ManagementFinalizer
Illustration of a C# destructor symbol with a garbage collector and a clock, representing nondeterministic finalization.
C#

Understanding C# Destructors and Finalization

Learn how C# destructors (finalizers) work, when they run, and why IDisposable is usually the better cleanup mechanism.

C#FinalizerIDisposableGarbage Collection
Illustration of a C# finalizer method being invoked by the garbage collector during memory reclamation
C#

C# Finalizer: How It Works and When to Use It

Understand C# finalizers: syntax, runtime behavior, interaction with garbage collection, and when to use them for resource cleanup.

finalizergarbage collectionIDisposableresource management
Illustration of an async disposal pattern in C# showing a resource being released with an await using statement.
C#

C# IAsyncDisposable for Async Resource Cleanup

Learn how to implement IAsyncDisposable in C# to release resources asynchronously, with practical examples and common pitfalls.

async disposalresource managementawait usingIDisposable