Home / Forums / How to use C# 10 Record Structs vs Standard Structs for Game Math [Discussion #7]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

How to use C# 10 Record Structs vs Standard Structs for Game Math [Discussion #7]

KernelGamer
C++ / Driver Dev
MEMBER
Rep: 340
Join Date: Sep 2022
Posts: 6
Thanks: 18
3y ago · Sep 7, 2022 7:12 PM
#1
Sharing a comparison between record struct and standard struct in C# 10+. Record structs automatically generate value-based equality, GetHashCode, ToString, and with { } non-destructive mutation expressions.
KernelGamer · C++ / Driver Dev
Windows Internals, system threads, and high-frequency game l...
The following users thanked KernelGamer for this post:
Algorithmic
Math & Algorithms
MEMBER
Rep: 45
Join Date: Jan 2020
Posts: 6
Thanks: 55
3y ago · Sep 7, 2022 10:27 PM
#2
The with { } operator on record structs is so clean: var moved = point with { X = point.X + 10 }; It copies the struct on the stack with the modified field in one line.
Algorithmic · Math & Algorithms
Linear algebra, pathfinding, binary spatial partitioning, an...
DirectX_Pro
DirectX 11/12 Engineer
MEMBER
Rep: 69
Join Date: Aug 2021
Posts: 6
Thanks: 93
3y ago · Sep 8, 2022 1:27 AM
#3
Also remember readonly record struct makes the data completely immutable, which helps the JIT optimize register allocation!
DirectX_Pro · DirectX 11/12 Engineer
Direct3D pipelines, compute shaders, and swap chain presenta...