Avoiding Boxing with Struct Dictionary Keys in C#: Performance and Best Practices

Discover why structs as dictionary keys can cause hidden allocations in C#. Learn how to implement IEquatable, use readonly and record structs, and write allocation-free, high-performance code for hot paths.

July 6, 2025 · 4 min · 695 words · Abhinaw

What is Boxing and Unboxing in C#?

If you’ve been coding in C# for a while, you’ve probably heard about boxing and unboxing. These concepts deal with how C# handles conversions between value types and reference types, and they can significantly impact your application’s performance. What’s the Difference Between Value and Reference Types? In C#, value types (like int, float, struct) live on the stack, while reference types (like string, object, classes) live on the heap. This distinction matters for performance and memory management. ...

June 20, 2025 · Last modified: June 23, 2025 · 2 min · 390 words · Abhinaw