Search Unity

Named out parameters. How to call them?

Discussion in 'Scripting' started by rawegames, Oct 21, 2016.

  1. rawegames

    rawegames

    Joined:
    Aug 1, 2016
    Posts:
    91
    myfunc:
    Code (csharp):
    1.  
    2. void myfunc(string s, out int x){
    3.    Debug.Log(s);
    4.    x = 123;
    5. }
    6.  
    Calling myfunc:
    Code (csharp):
    1.  
    2. int i;
    3. myfunc(s: "abc",x: out i);
    4.  
    upload_2016-10-22_2-33-18.png

    Calling myfunc:
    Code (csharp):
    1.  
    2. int i;
    3. myfunc(s: "abc",out x: i);
    4.  
    upload_2016-10-22_2-36-17.png

    I can't find the right syntax.

    How do I call a function using named arguments, with an optional parameter?
     
  2. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    293
    'out' does not specify an optional parameter, but an output parameter.

    In any case, naming output prameters doesn't seem to be possible in the version of .net Unity uses. The correct syntax would be 'x: out i'. But named variables are only useful for optional parameters really (apart from readability). VS/Resharper complains to me that the name identifier is redundant.
     
    Last edited: Oct 21, 2016