Please enable JavaScript.
Coggle requires JavaScript to display documents.
04 Parameter passing options (OUT parameters (Same underlying mechanism…
04
Parameter passing
options
Default
parameter passing
mechanism
Pass by value
For value types, methods receive
copy of actual value
For reference types, methods receive
copy of reference to object in memory
OUT parameters
Same underlying mechanism as REF parameters
except the compiler only allows you to set the value
within the method
Method can only read the parameter after it's
assigned it a value
Compiler checks all code paths assign a value to
the OUT parameter at some point before exit
Can be used in addition to return values
to effectively return two pieces of information
TryParse methods
bool Int32.TryParse(string s, out int result)
Returns true if int parsed OK, else false
If int parsed OK, value written to result
If not parsed OK, result set to zero
REF parameters
For value types, called method receives
reference to the location in memory of
the caller's variable holding the value
For reference types, called method receives
a reference to the location in memory of
the caller's variable holding its reference to
the object in memory!
Must specify REF both when method is defined
and when method called (to help the human reader)
Labs
Kid in a Candy Store (part 2)
Council tax calculations
Swap routines