Forum Discussion

mkirkland's avatar
mkirkland
Contributor
14 years ago

C# script out parameters?

I see some help documentation about out parameters with Delphi but nothing in any other languages.



Is there anything to support out parameters in C# scripting? I can use the 'return true;' but i want more parameters than two..

would be similar to: function TableItems(TableAlias, ItemToSearch, ColToSearch, MinusRowAmt, out string Param1, out string Param2)

{

//......stuff here

  • I was able to just add a 'Unit reference' to my other scripts and then create a few global variables in the main script that is being referenced. So with that i can call my method from any other script routine and use the global variables as my out parameters.



    Worked like a charm! :)
  • Matt,


    C#Script is based on JScript and the latter does not support out parameters, so you have to search for workarounds.


    I'm glad to hear you have found a solution. A possible alternative to global variables is using arrays (see the code snippet below). You pass an array as a parameter to your function and change the array elements in it. The arrays are passed by reference, so you can use your array's elements after your function returns.




    function Caller()

    {

      // Create an array

      var arr = new Array(4);

      arr[0] = 10;

      arr[1] = true;

     

      // Call your function

      Callee(arr);

     

      // Check out parameters

      Log.Message(arr[2]);

      Log.Message(arr[3]);


    }


    function Callee(arr)

    {

      // Use the in parameters somehow

      Log.Message(arr[0]);

      Log.Message(arr[1]);

     

      // Set the out parameters

      arr[2] = "Hello!";

      arr[3] = 123;

    }