web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Adding "byRef" parameter to function

(0) ShareShare
ReportReport
Posted on by

Hello,

What is the equivalent to C#  in X++?

int myfunc(byref x)

{

}

 

I want to change the x value in myfunc, in order the calling function would get the new value passed as a parameter.

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi, you need to look at parm methods and args.  Refer to almost any AX class to see how to use this.

  • Suggested answer
    Denis Patrakov Profile Picture
    on at

    There is a "byref" keywork in X++ but it's only intended for CLR interop (to match a signature of a method that requires a parameter to by passed byref). For X++ code you should pass an argument of a reference type if you want the changes to be "visible" in the calling code. For arguments of value types such as int/date/str you can use a "wrapper" - see SysAnyType class.

  • Community Member Profile Picture
    on at

    I know those methods.

    Isn't any other common way to send "byref" parameters to function (that can be changed, as C#, v.b, etc. does) ?

    Thanks :)

  • Suggested answer
    Hossein.K Profile Picture
    6,648 on at

    Hi Eitan Mizrahi ,

    You can use the X++ keyword byref to call .NET methods that take parameters by reference.

    In all X++ methods, all parameters are passed by value. In .NET, parameters can be passed by value or by reference.

    You must understand the parameter passing concepts of by value versus by reference before you can correctly use the byref keyword.

    You can use this link :

    msdn.microsoft.com/.../cc586700.aspx

    kind regards

  • Suggested answer
    Amir Kaftari Profile Picture
    210 on at

    Hi Eitan.

    The following code example has a section for the X++ caller method and a section for the C# called method. The called method adds 456 to its parameter variable iTest. The caller method can detect that the addition occurred.

    Caller Method :

    public void CallerMethodByReferenceInt // X++
    
    {
    
       int iTest = 3;
    
       ;
    
       TheNamespace.DemoClassNet::CalledMethodByReferenceInt
    
               (byref iTest);
    
       if (iTest == 459)
    
       {
    
           info("Good, == 459.")
    
       }
    
    }


    Called Method :

    static public void CalledMethodByReferenceInt // C#
            (ref int iTest) // by reference
    {
        iTest = iTest + 456; // Caller can detect.
    }
    


    I hope to be used.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans