In and Out Parameters and Migrated Style Parameters
- Let's examine the "in" and "out" nature of the different parameters
public void Run()
{
Number myValue = 5;
NumberColumn myColumn = new NumberColumn();
myColumn.Value = 7;
MethodA(myValue);
MethodA(myColumn);
- //MethodB(myValue); //this line would not work, since you can't send a value to a parameter of type column
MethodB(myColumn);
MethodC(myValue);
MethodC(myColumn);
}
void MethodA(Number value)
{
Debug.WriteLine(value);
value++;
}
void MethodB(NumberColumn column)
{
Debug.WriteLine(column);
column.Value++;
}
void MethodC(NumberParameter parameter)
{
Debug.WriteLine(parameter);
parameter.Value++;
}
Let's review the execution of this code:
- In line 3 we set the value of
myValue
to5
. - In Line 5 we set the value of
myColumn
to7
. - In line 6 we call
MethodA
and send it the value5
(from the fieldmyValue
)- In line 15, the parameter called
value
now has the value5
- In Line 17 we write the value received as a parameter (
5
) to the "output" window - In Line 18 we change the value of the parameter called
value
to6
. - Since
value
is of typeNumber
(a "Value" type) that change is local to this method - and will not affect the actual value in the fieldmyValue
whenMethodA
is done executing.
- In line 15, the parameter called
- In line 6, once the
MethodA
is completed, the value in themyValue
field stays the same as before the call -5
- In line 7, we call
MethodA
and send itmyColumn
. SincemyColumn
is a column, andMethodA
receives aNumber
(a "Value" type), the code implicitly sendsmyColumn.Value
, which means send the value stored inmyColumn
(7
)- In Line 15, the parameter called
value
now has the value7
- In Line 17 we write the value received as a parameter (
7
) to the "output" window - In Line 18 we change the value of the parameter called
value
to8
. - Since
value
is of typeNumber
(a "Value" type) that change is local to this method - and will not affect the actual value in the columnmyColumn
whenMethodA
is done executing.
- In Line 15, the parameter called
- Line 9 is skipped, because we can't send a "Value" type to
MethodB
which accepts only "Column" types - In line 10, we send the column in the field
myColumn
(that has the value7
) toMethodB
- In line 20 the parameter called
column
references to the same Column as the one in the fieldmyColumn
. This means that any change to theValue
ofcolumn
will be affect theValue
ofmyColumn
since both are actually the same Column. - In Line 22 we write the value received as a parameter (
7
) to the "output" window - In Line 23 we change the
Value
of the column referenced by the parametercolumn
to8
. - Since
column
is a Column type (NumberColumn
) when we change it'sValue
we change the value of the column that was sent.
- In line 20 the parameter called
- In line 10, once
MethodB
completed, the value in the columnmyColumn
is now 8, as the column itself was sent toMethodB
Migrated style parameters, NumberParameter
- In line 12 we are sending the "Value" in
myValue
(5
) toMethodC
that accepts aNumberParameter
- In line 25, the
parameter
parameter now has the value5
as was sent to it in line 12. - In Line 27 we write the value received as a parameter (
5
) to the "output" window - In Line 28 we change the value of the parameter called
parameter
to6
. - Since on line 12, we send a "Value" to
MethodC
any change made inMethodC
is limited to it's scope and will not affect the value once we exitMethodC
- In line 25, the
- In line 12, once
MethodC
is complete - the value ofmyValue
remains5
. - In line 13, we are sending the "Column" in
myColumn
(value8
) toMethodC
- In line 25 the parameter called
parameter
references to the same Column as the one in the fieldmyColumn
. This means that any change to theValue
ofparameter
will be affect theValue
ofmyColumn
since both are actually referencing to the same Column. - In Line 27 we write the value received as a parameter (
8
) to the "output" window - In Line 28 we change the
Value
of the parameter referenced by the parameterparameter
to9
. - Since
parameter
is aNumberParameter
and on line 13, we sent it a "Column", when we change it'sValue
we change the value of the column that was sent.
- In line 25 the parameter called
- In line 13, after
MethodC
is complete, the value of the column referenced inmyColumn
field is now9
Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com