Avatar ·

When to use struct instead of class in C#? Understanding value types

Hi everyone! I recently started learning C# and I constantly get confused when I need to choose between struct and class. They seem similar — both allow you to declare fields, methods, properties. But I've heard that struct is a value type, while class is a reference type, and this greatly affects performance. I have a specific task: I'm writing a small 2D engine for games. I have a Point structure with X and Y coordinates. Currently it's declared as a class: ```csharp public class Point { public int X { get; set; } public int Y { get; set; } public Point(int x, int y) { X = x; Y = y; } } ``` Everything works, but I create thousands of such points every frame, and the application starts to lag. A friend advised me to replace class with struct to speed things up. But I'm b