Skip to content
BENIBIX Learn

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.

Development🧭 Programming Paradigms

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.

Example
A game keeps each bullet as a struct with x, y and speed. Thousands of them fit in memory and move fast.
Why it matters
Structs make small bits of data easy to pass around and name. In many languages they are also fast and light.
Full entry
Development🧭 Programming Paradigms

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.

Example
Emma writes a Dog class with a name and a speak method. She makes a dog called Rex from it, and Rex says woof.
Why it matters
Classes let you write the shape of a thing once and reuse it everywhere.
Full entry

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.