# Cyrille37 # wrote:
can anyone give specific examples where structs are preferred to classes?
I'm not a master of code, but I use struct for grouping variables without need
of methods.
Like Event data and more generally composite parameters.
IMO, that's not a good way of deciding whether to use a struct or a
class. What you should be looking at is the semantics of structs and
classes, and that doesn't affect whether or not you have methods.
For me, the questions are (at least):
1) Is this a sort of low level "atomic" type? That would *suggest* a
value type (struct)
2) Is the data potentially large? (Direct data only) That would
*suggeste* a reference type (class)
3) Do you need the type to be mutable? That would almost always suggest
a reference type.
It's more than that, and you tend to get a feel for it, but those are
good starting questions IMO. The "default" position should almost
always be to use a class. I very rarely introduce my own structs.
Jon