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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

HexRays99
Senior Reverse Engineer
VIP
Rep: 380
Join Date: Apr 2022
Posts: 36
Thanks: 94
4y ago · Mar 25, 2022 9:30 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.
HexRays99 · Reverse Engineering & Static Analysis
CPP
// Always check your pointers!
if (!pLocalPlayer) return;
The following users thanked HexRays99 for this post:
RenderMaster
ImGui UI Designer
VIP
Rep: 310
Join Date: Sep 2023
Posts: 32
Thanks: 82
4y ago · Mar 25, 2022 12:01 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.
RenderMaster | Clean UI Design & Dear ImGui widgets
RustMechanic
Unity & IL2CPP Reverser
VIP
Rep: 295
Join Date: Nov 2022
Posts: 32
Thanks: 74
4y ago · Mar 25, 2022 3:01 PM
#3
Also remember readonly record struct makes the data completely immutable, which helps the JIT optimize register allocation!
RustMechanic | IL2CPP & Unity Engine Analysis