Struct vs Class
A struct is a simple bundle of named values. In C#, Swift and Go it is copied when you pass it. A class object is shared, so a change shows everywhere.
Struct
A simple type that groups a few named values, like x and y of a point.
A struct groups a few named values into one new type. A Point struct might hold x and y. It is like a simple class, often with data and few or no methods. C, C#, Go, Rust and Swift all have structs. In C#, Swift and Go, a struct is usually copied when you pass it, while a class object is shared.
Class
A plan for making objects. It lists their data and their actions.
A class is a plan for making objects of one kind, like dogs or players. It says what data each object will hold and what actions it can do. The class itself is just the plan; each object made from it is real and has its own values. In most languages a class name starts with a capital letter. You use the class name to make a new object.
In one line
- Struct
- A simple type that groups a few named values, like x and y of a point.
- Class
- A plan for making objects. It lists their data and their actions.