Menu

keywords-out

Will Pittenger

The out and ref keywords do pretty much the same thing: Tell the compiler than a type must be passed by reference. There are difference though. The ref keyword always adds a reference layer so that even if the type already is a reference type, it gets an extra layer of reference. The out keyword will only add a reference layer if the type defaults to a by-value type. Furthermore, out can only be used on var parameters that aren't declared as readonly. Finally, out tells the compiler the procedure the out parameter is being passed to will initialize the variable. This allows the procedure to return an extra value. Please note that out can't be directly combined with byvalue or ref. For that, you need a typealias as described in [Type aliases]. If a formal parameter was declared with out, the corresponding actual parameter must be preceded with out.

/StartOfDeclarationSequenceForProcedure/ \var\ \out\ /identifier/ /EndOfDeclarationSequenceForProcedure/

For more on what can be in a declaration sequence, see Declaration sequences. The following sample shows how to use out for an actual parameter.

(\ref\ | \out\ | \byvalue\) /identifier/

Related

Wiki: Appendices-Terms-Type descriptors
Wiki: By value versus by reference
Wiki: Complex Statements
Wiki: Custom operators
Wiki: Keywords
Wiki: Type aliases
Wiki: keywords-byvalue
Wiki: keywords-readonly
Wiki: keywords-ref
Wiki: keywords-var