Inlining and structs in C#
In this - somewhat technical and barely usable - blog post, we will have a look at inlining and structs in C#. And how they can optimize performance in some interesting ways.
In this - somewhat technical and barely usable - blog post, we will have a look at inlining and structs in C#. And how they can optimize performance in some interesting ways.
You might have heard that mutable value types are evil. But why is that and why does the .NET framework use them then? Are they really that evil?
Let's have a look at a few examples and have a look what is going on!
C# 11 brings some major improvements for structs. You remember Span<T>
, which you couldn't create?
Now you can. C# 11 allows ref
fields in a struct. Why this is a cool thing and what you can do with it, you will see in a minute.
There are multiple ways to create a new struct, either via var myStruct = default(MyStruct)
or via var myStruct = new MyStruct();
. Are there any differences?
C# knows struct
since its down of time. But there are also recent additions like readonly struct
, record struct
and ref struct
.
This article will show what are the differences between those 4.
Let's have a small look into struct
s and how they work when using Equals
and GetHashCode
. Plus have a brief look into a new C# 10 feature: readonly record struct
.