
Structs have their advantages in .NET: they are especially efficient in the runtime if used correctly.
But if you use structs with an interface, the massive advantages unfortunately turn into disadvantages:
As soon as an interface is attached to a struct, Boxing
comes into effect; the values are thus copied over and over again, which is usually not what you want - but it also shows up in the benchmarks.
1BenchmarkDotNet=v0.13.2, OS=Windows 10 (10.0.19044.2486/21H2/November2021Update)
2AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
3.NET SDK=7.0.200-preview.22628.1
4 [Host] : .NET 6.0.13 (6.0.1322.58009), X64 RyuJIT AVX2
5 DefaultJob : .NET 6.0.13 (6.0.1322.58009), X64 RyuJIT AVX2
6
7
8| Method | Mean | Error | StdDev | Median | Gen0 | Allocated |
9|-------------------- |----------:|----------:|----------:|----------:|-------:|----------:|
10| Class | 2.9964 ns | 0.0713 ns | 0.0667 ns | 3.0374 ns | 0.0014 | 24 B |
11| ClassWithInterface | 3.0590 ns | 0.1043 ns | 0.0976 ns | 3.0742 ns | 0.0014 | 24 B |
12| Struct | 0.0018 ns | 0.0030 ns | 0.0023 ns | 0.0012 ns | - | - |
13| StructWithInterface | 3.1241 ns | 0.0835 ns | 0.0781 ns | 3.1147 ns | 0.0014 | 24 B |
In principle, this behavior is nothing new. Potential solutions are already being worked dotnet/csharplang - Proposal: Allow readonly ref structs to implement interfaces, but disallow boxing them #1479 on so that structs can be used boxing-free.
Related articles

Mar 10, 2026 · 15 min read
.NET NuGet Trusted Publishing with GitHub Actions
Publishing NuGet packages has traditionally required one uncomfortable compromise: a long-lived API key had to exist somewhere in the …

Mar 09, 2026 · 7 min read
C# 15 Unions: Unions are finally in .NET
After many years of workarounds, design discussions and library-level substitutes, unions are finally becoming a first-class part of C#. The …

Mar 02, 2026 · 19 min read
Unio: High-Performance Discriminated Unions for C#
C# is a powerful language, but there is one road it has not yet fully paved: native discriminated union types. Developers have been working …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

Comments