Structs are value types

suggest change

Unlike classes, which are passed by reference, structures are passed through copying:

var first = "Hello"
var second = first
first += " World!"
// first == "Hello World!"
// second == "Hello"

String is a structure, therefore it’s copied on assignment.

Structures also cannot be compared using identity operator:

window0 === window1 // works because a window is a class instance
"hello" === "hello" // error: argument type 'String' expected to be an instance of a class or class-constrained type

Two struct values have no identity to compare. They are interchangeable when == says they are equal, if the type implements that operator.

These differences from classes are what make structs value types.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents