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
Flowchart comparing traditional and primary constructor syntax across C# classes, structs, and records

Primary Constructors in C# 12: Simplified Class Design for Classes, Structs, and Records

Introduction to Primary Constructors in C# 12 C# 12 brings us primary constructors, and honestly, they’re changing the way I write classes, structs, and records. With this feature, you can put constructor parameters right in the class declaration instead of creating a separate constructor method. The result? Way less code that’s much easier to read. Let’s face it, we’ve all written the same constructor code hundreds of times. You know the drill: declare parameters, create private fields, assign values in the constructor body. It’s tedious and easy to mess up. That’s exactly the problem primary constructors solve. ...

June 21, 2025 · 6 min · 1149 words · Abhinaw