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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

How to use C# 10 Record Structs vs Standard Structs for Game Math

KronoDev
C++ / Game Modder
MEMBER
Rep: 195
Join Date: Jan 2023
Posts: 32
Thanks: 48
4y ago · Mar 7, 2022 10:18 AM
#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.
KronoDev - Keep coding, keep learning
The following users thanked KronoDev for this post:
DarkLogic
Game Logic & SDK Developer
MEMBER
Rep: 180
Join Date: Jun 2024
Posts: 28
Thanks: 41
4y ago · Mar 7, 2022 11:29 AM
#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.
DarkLogic | Virtual method tables & SDKs
SigScannerPro
Pattern Scanning & IDA
MEMBER
Rep: 210
Join Date: Jul 2023
Posts: 25
Thanks: 52
4y ago · Mar 8, 2022 5:29 PM
#3
Also remember readonly record struct makes the data completely immutable, which helps the JIT optimize register allocation!
SigScannerPro · Pattern scanning & Byte masking