Browse by Topic

Popular

Latest

Latest Posts

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
Illustration of a C# object being hashed into a bucket array in a dictionary.
C#

C# GetHashCode: Contract and Correct Overrides

Learn how GetHashCode works in C#, why it matters for Dictionary and HashSet, and how to override it correctly alongside Equals.

GetHashCodeEqualityDictionaryHashSet
Diagram showing two object references pointing to the same memory location versus two separate objects with equal values.
C#

Understanding C# Object Equals: Reference vs Value Equality

Learn how object.Equals works in C#, when to override it, and how to implement value equality correctly with GetHashCode and IEquatable<T>.

C# equalityObject.EqualsGetHashCodeIEquatable<T>
Diagram showing two object references pointing to the same memory location, illustrating ReferenceEquals in C#.
C#

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

Learn how ReferenceEquals compares object identity in C#, how boxing affects value types, and when to use it instead of == or Equals.

ReferenceEquals
A visual comparison of the C# equality operator and Equals method showing reference versus value equality
C#

C# == vs Equals: How They Differ and When to Use Each

Learn how the C# == operator and Equals method differ for reference types, value types, and strings, and when to override or overload them.

C#EqualityOperator OverloadingValue Types
Diagram showing two object boxes with an equals sign, one pair identical, the other different, illustrating C# equality comparison.
C#

C# Equality Comparison: Value vs. Reference Types

Learn how C# equality comparison works for value and reference types, including Equals, GetHashCode, operator overloading, IEquatable<T>, and records.

C# EqualityValue TypesReference TypesIEquatable<T>
C# code showing the discarded underscore character being used to ignore an out parameter, with a visual emphasis on the underscore symbol.
C#

Using the C# Discard Operator Effectively

Learn how to use the C# discard (`_`) to ignore unwanted values in assignments, out parameters, tuple deconstruction, and pattern matching, with practical examples.

C#discard operatortuple deconstructionpattern matching
Illustration of a C# object splitting into multiple variables through a Deconstruct method.
C#

C# Deconstruct Method: Syntax and Use Cases

Learn how to implement and use the C# Deconstruct method to unpack objects and tuples into individual variables, including syntax, overloads, pattern matching, extension methods, and common pitfalls.

DeconstructionC# SyntaxTuplesPattern Matching