Structs
Context: Structs are value types that can contain data and methods. They are suitable for small, lightweight objects.
Structs are allocated on the stack (or inline in heap objects) and are copied on assignment.
public struct Point{ public int X; public int Y; public Point(int x, int y) { X = x; Y = y; }}Real-world usage example
Section titled “Real-world usage example”Vector math in game development: Use structs for Vector2, Vector3, Matrix4x4 to avoid garbage collection overhead and improve performance.
Example: In Unity, Vector3 is a struct. In .NET, System.Numerics.Vector3 is also a struct.