Browse by Topic

Popular

Latest

Latest C# Posts

Diagram illustrating shallow copy vs deep copy in C# with MemberwiseClone
C#

C# MemberwiseClone: Shallow Copy Basics

Learn how C# MemberwiseClone creates shallow copies, why nested objects are shared, and when a deep copy is necessary.

MemberwiseCloneObject CloningShallow CopyICloneable
Diagram of shallow copy and deep copy of an object graph in C#.
C#

C# Shallow Copy vs Deep Copy

Understand the difference between shallow and deep copying in C#, how to implement each, and when to choose one over the other.

C#Object CopyingMemberwiseCloneDeep Copy
Diagram showing a value type being boxed into an object reference and later unboxed back to a value type.
C#

C# Object Casting and Boxing: How Type Conversion Works

Understand how C# object casting and boxing work, the runtime cost of boxing, common unboxing errors, and when to prefer generics over object conversions.

C#BoxingType CastingPerformance
Diagram showing a value type being boxed into a heap object with an arrow indicating the allocation overhead.
C#

C# Boxing Performance: Avoiding Hidden Allocations

c# boxing performance: Learn how boxing affects C# performance, where hidden allocations occur, and how generics help you avoid them in hot paths.

boxingunboxinggenericsmemory allocation
Illustration showing a boxed value (object) being opened to reveal the original value type inside, with C# and .NET purple color palette.
C#

Demystifying C# Unboxing

Practical C# unboxing guide: runtime mechanics, InvalidCastException pitfalls, nullable value behavior, and generic alternatives that reduce boxing.

.NETType CastingBoxingPerformance
Diagram showing a value type box being wrapped into a heap object with a reference pointer.
C#

C# Boxing Examples: How Value Types Behave

c# boxing examples: Understand C# boxing with practical examples: what happens on the heap, why unboxing requires exact type casts, and how to avoid boxing with generics.

boxingunboxingvalue typesgenerics
Illustration showing a value type boxed into a reference type object and unboxed back, with a warehouse metaphor for heap allocation.
C#

C# Boxing vs Unboxing: How They Affect Performance

Understand how C# boxing and unboxing work, why boxing can add allocations, and how to reduce unnecessary conversions in performance-sensitive code.

BoxingUnboxingPerformanceValue Types
An illustration of sorting cards by a custom rule, showing unordered cards on the left and neatly stacked sorted cards on the right.
C#

C# Custom Sorting with Comparers and LINQ

Learn how to implement custom sorting in C# with IComparer, Comparison delegates, and LINQ OrderBy, including practical examples and performance considerations.

IComparerLINQ OrderBySort()Comparison delegate
Illustration of two lists being sorted and deduplicated using custom comparer logic in C#.
C#

Creating Custom Comparers in C# for Sorting and Equality

Learn how to create custom comparers in C# to control sorting and equality in LINQ, collections, and dictionaries.

IComparerIEqualityComparerComparer<T>Sorting
A diagram showing two objects compared with an equals sign, representing IEquatable<T> equality comparison in C#.
C#

Implementing IEquatable<T> in C# for Efficient Equality Checks

Implement IEquatable<T> in C# to define typed equality checks, avoid boxing for structs, and keep hash-based collections consistent. Includes examples for value types and reference types, plus common pitfalls.

IEquatableEqualityC#GetHashCode