Reference Operator (&)

The & operator is used to pass references to variables to methods with reference or out parameters. Changes to the parameter in the method are reflected in the variable that was passed by reference when control passes back to the calling method.

&expression

Parameters

  • expression
    A variable passed to the method.

Remarks

JScript can call methods with reference and out parameters, but it cannot define them.

Example

The following example illustrates a use of the Reference (&) operator.

// Define Compute method in C# code.
public class C 
{
    public static void Compute(ref int sum, out int product, int a, int b) 
    {
        sum = a + b;
        product = a * b;
    }
}

// Call Compute method from your JScript code.
var a : int, b: int;
C.Compute(&a, &b, 2, 3)
print(a);
print(b);

See Also

Reference

ref (C# Reference)

out (C# Reference)