Menu

keywords-readonly

Will Pittenger

Marks a var or typealias as read only. Anything readonly can be initialized, but then never changed again as long as they remain in scope. If the item is a reference type, readonly only has an effect on the outermost reference whereas const would only have an effect on what the reference points to. If the item is a by-value type, readonly is the same as const when combined with var. Variables of type expression can't be made readonly.

Variables

\var\ [\readonly\] [\const\] [(\ref\ | \byvalue\)] /TypeDescriptor/ /identifier/ [\=\ /Value/]

For more on what /TypeDescriptor/ can be, see Type descriptors.

Type aliases

\typealias\ [\readonly\] [\const\] [(\ref\ | \byvalue\)] /TypeDescriptor/ /identifier/

Related

Wiki: Keywords
Wiki: keywords-const
Wiki: keywords-expression
Wiki: keywords-out
Wiki: keywords-returns
Wiki: keywords-set
Wiki: keywords-typealias
Wiki: keywords-var
Wiki: keywords-volatile