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# event with a custom EventArgs class carrying data between sender and handler.
C#

C# Custom EventArgs: Passing Data with Events

c# custom eventargs: Learn how to create custom EventArgs classes in C# to pass structured data with events, including design rules and memory behavior.

C#EventsEventArgsEvent Handling
Illustration of a C# event handler connecting a publisher and subscriber with a delegate arrow.
C#

C# EventHandler: Events, Subscriptions, and Pitfalls

Learn how to declare, raise, and subscribe to events with C# EventHandler, including custom event args, thread safety, exception isolation, and avoiding memory leaks.

C# EventsEventHandlerDelegates.NET
Diagram comparing C# event and delegate access and invocation rules
C#

C# Event vs Delegate: Key Differences

C# event vs delegate: Understand the technical difference between C# events and delegates, including invocation rules, assignment restrictions, and when to use each.

C#EventsDelegatesMulticast
Illustration of a C# event handler being removed from a publisher to prevent memory leaks.
C#

How to Unsubscribe from C# Events: Syntax and Memory Leak Prevention

Learn how to use -= to unsubscribe from C# events, avoid memory leaks, and manage event handler lifetimes with practical examples.

C# eventsevent handlersmemory leaksdelegates
Illustration of C# event subscription showing a publisher and subscriber connected by a delegate chain, with an emphasis on unsubscription to prevent memory leaks.
C#

C# Event Subscription: Syntax, Pitfalls, and Clean Unsubscription

Learn C# event subscription syntax, why unsubscribing matters, how to avoid memory leaks, and when to use lambda, method group, or weak event patterns.

C#eventsdelegatesmemory leaks
Illustration of a C# event declaration connecting an event source to multiple handler nodes.
C#

C# Event Declaration: Syntax, Behavior, and Pitfalls

Learn the syntax for declaring C# events, safe ways to raise them, and the difference between events and delegate fields.

C# eventsdelegatesevent handlersEventHandler<T>
A diagram showing a publisher object raising an event to multiple subscriber handlers in C#.
C#

C# Event Usage: Declaring, Raising, and Handling Events

Learn how to declare, raise, and handle events in C# with practical examples, thread-safety considerations, and memory-leak prevention.

C#EventsDelegatesEventHandler
Illustration of a C# lambda expression using an underscore discard for an unused parameter.
C#

C# Discard Lambda Parameter: When and How to Use It

Learn how C# 9 lambda discard parameters use `_` for unused inputs, when they improve clarity, and how they apply to delegates, event handlers, and LINQ.

C#Lambda ExpressionsDiscardsDelegates
Illustration of a C# static lambda symbol with a lock indicating no capture.
C#

C# Static Lambda: Syntax, Benefits, and Usage

Learn how C# static lambdas avoid capturing instance state, reduce allocations, and improve performance in delegate-heavy code.

C#Lambda ExpressionsStatic Anonymous FunctionsDelegates
Diagram illustrating how a C# lambda captures variables from its enclosing scope, forming a closure.
C#

C# Lambda Variable Capture: Closures and Pitfalls

Learn how C# lambda expressions capture variables, why foreach and for loops behave differently, and how closures affect memory and performance.

lambda expressionsclosuresvariable captureC# loops