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

A visual representation of the C# null coalescing assignment operator assigning a value only when the left operand is null.
C#

C# Null Coalescing Assignment Operator

c# null coalescing assignment operator: Learn how to use the C# null coalescing assignment operator (??=) to assign values only when a variable is null, with practical...

C#Null CoalescingNull HandlingAssignment
Illustration of the C# modulo operator showing division and remainder on a number line.
C#

C# Modulo Operator: Syntax and Common Pitfalls

A practical look at the C# modulo operator: integer and floating-point behavior, negative operands, common pitfalls, and useful code examples.

C#modulointeger arithmeticfloating-point
Illustration of C# arithmetic operators with mathematical symbols and code context.
C#

C# Arithmetic Operators: Syntax, Behavior, and Pitfalls

How C# arithmetic operators behave in practice: integer division truncation, overflow handling, floating-point precision limits, and operator precedence.

C#arithmetic operatorsinteger overflowoperator precedence
Illustration of integer overflow wrapping around versus throwing OverflowException in C#
C#

C# Overflow Handling with checked and unchecked

How C# handles integer overflow by default, how the checked and unchecked contexts change that behavior, and how to enable project-wide overflow checking.

checkeduncheckedOverflowExceptioninteger arithmetic
Illustration of the C# Convert class transforming a value into different data types such as string, integer, and boolean.
C#

C# Convert Usage: Converting Between Base Types

How to use the C# Convert class for type conversion, including null and DBNull handling, culture behavior, and when to choose Convert, Parse, TryParse, or casting.

C#.NETtype conversionConvert class
A magnifying glass over a C# class diagram highlighting method names, representing reflection retrieving methods at runtime.
C#

How to Get Methods with C# Reflection

Learn how to retrieve method metadata with C# reflection, use BindingFlags to filter results, resolve overloads, and cache MethodInfo for better performance.

ReflectionMethodInfoType InspectionRuntime Metadata
Diagram showing an interface bridging a generic method and multiple type instances, representing C# type class emulation.
C#

C# Type Class: Emulating with Interfaces

C# Type Class: Learn how to emulate type classes in C# using interfaces, generic constraints, and static generic classes, with tradeoffs and decision criteria.

C#Type ClassesInterfacesGeneric Constraints
A comparison diagram showing the C# typeof operator resolving a type at compile time and the GetType method discovering the runtime type of an object instance.
C#

C# typeof vs GetType: Compile-Time vs Runtime Type Resolution

The typeof operator resolves types at compile time, while GetType() discovers an object's runtime type. Includes code examples for inheritance, generics, interfaces, and null handling.

C#Type SystemReflectionRuntime Type
A magnifying glass inspecting a C# object to reveal its runtime Type, symbolizing reflection GetType.
C#

C# Reflection GetType: Inspect Runtime Types

Learn how to use C# reflection GetType to inspect runtime types, compare it with typeof, and avoid common pitfalls in real-world code.

C# ReflectionGetType MethodType ObjectRuntime Type Inspection
C# code snippet showing the typeof operator returning a Type object, with reflection metadata elements around it
C#

C# Reflection: typeof in Practice

Learn how to use C#'s typeof operator with reflection: getting Type metadata, inspecting members, handling generics and nullable types, and caching reflection results for performance.

reflectiontypeof operatorSystem.Typeruntime type inspection