Partager via


Calling Methods That Take Arguments By Reference 

The .NET Framework has support for passing parameters by reference. In this case, the parameter can be modified inside the function and these changes are visible to the caller. Visual J# follows the C++ style where you can directly call the method and pass the parameter, and the Visual J# compiler does the conversion implicitly.

Example

// vjc_args_by_ref_1.cs
// compile with: /target:library
// A C# program used as a DLL
public class MyClass1
{
    public void Test(ref string str)
    {
        str += " World!";
    }
} 

You can call this method in the Java language as follows:

// vjc_args_by_ref_2.jsl
// compile with: /reference:vjc_args_by_ref_1.dll
public class MyClass2
{
    public static void main(String [] args)
    {
        MyClass1 x = new MyClass1();
        System.String mystr = "Hello";
        System.Console.WriteLine(mystr);
        x.Test(mystr);
        System.Console.WriteLine(mystr);
    }
}

Output

Hello
Hello World!

See Also

Reference

Syntax for Targeting the .NET Framework
Language Extensions to Support the .NET Framework