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
myValueto5. - In Line 5 we set the value of
myColumnto7. - In line 6 we call
MethodAand send it the value5(from the fieldmyValue)- In line 15, the parameter called
valuenow 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
valueto6. - Since
valueis of typeNumber(a "Value" type) that change is local to this method - and will not affect the actual value in the fieldmyValuewhenMethodAis done executing.
- In line 15, the parameter called
- In line 6, once the
MethodAis completed, the value in themyValuefield stays the same as before the call -5 - In line 7, we call
MethodAand send itmyColumn. SincemyColumnis a column, andMethodAreceives aNumber(a "Value" type), the code implicitly sendsmyColumn.Value, which means send the value stored inmyColumn(7)- In Line 15, the parameter called
valuenow 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
valueto8. - Since
valueis of typeNumber(a "Value" type) that change is local to this method - and will not affect the actual value in the columnmyColumnwhenMethodAis done executing.
- In Line 15, the parameter called
- Line 9 is skipped, because we can't send a "Value" type to
MethodBwhich 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
columnreferences to the same Column as the one in the fieldmyColumn. This means that any change to theValueofcolumnwill be affect theValueofmyColumnsince 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
Valueof the column referenced by the parametercolumnto8. - Since
columnis a Column type (NumberColumn) when we change it'sValuewe change the value of the column that was sent.
- In line 20 the parameter called
- In line 10, once
MethodBcompleted, the value in the columnmyColumnis now 8, as the column itself was sent toMethodB
Migrated style parameters, NumberParameter
- In line 12 we are sending the "Value" in
myValue(5) toMethodCthat accepts aNumberParameter- In line 25, the
parameterparameter now has the value5as 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
parameterto6. - Since on line 12, we send a "Value" to
MethodCany change made inMethodCis limited to it's scope and will not affect the value once we exitMethodC
- In line 25, the
- In line 12, once
MethodCis complete - the value ofmyValueremains5. - In line 13, we are sending the "Column" in
myColumn(value8) toMethodC- In line 25 the parameter called
parameterreferences to the same Column as the one in the fieldmyColumn. This means that any change to theValueofparameterwill be affect theValueofmyColumnsince 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
Valueof the parameter referenced by the parameterparameterto9. - Since
parameteris aNumberParameterand on line 13, we sent it a "Column", when we change it'sValuewe change the value of the column that was sent.
- In line 25 the parameter called
- In line 13, after
MethodCis complete, the value of the column referenced inmyColumnfield is now9
Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com