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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

BlazorKing
Full-Stack C#
MEMBER
Rep: 199
Join Date: Oct 2023
Posts: 6
Thanks: 26
3y ago · Sep 25, 2022 1:36 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.
BlazorKing · Full-Stack C#
Building real-time web applications and desktop tools with B...
The following users thanked BlazorKing for this post:
UI_Wizard
ImGui Widget Dev
MEMBER
Rep: 72
Join Date: Feb 2021
Posts: 6
Thanks: 95
3y ago · Sep 25, 2022 5:04 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.
UI_Wizard · ImGui Widget Dev
Writing complex custom ImGui widgets: color pickers, curve e...
MemoryLeaker
C++ Enthusiast
VIP
Rep: 182
Join Date: Sep 2022
Posts: 6
Thanks: 20
3y ago · Sep 25, 2022 11:04 PM
#3
Also remember readonly record struct makes the data completely immutable, which helps the JIT optimize register allocation!
MemoryLeaker · C++ Enthusiast
Always remembering to delete my heap pointers... most of the...