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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ method parameter can be reference object, and return value

(0) ShareShare
ReportReport
Posted on by 1,559

Hi Friends,

Can method parameter be 'reference' object, which can return value after set inside method?

Thanks,

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 1 on at

    all classes extending from AXInetrnalBase are having such methods, which set and return value.

    e.g. AXSalesTable (Class), AXCustTable (Class)

    robertxliang.blogspot.com/.../axinternalbase-class.html

    dynamicsaxbr.tumblr.com/.../ax-class-parte-2

  • Martin Dráb Profile Picture
    240,061 Most Valuable Professional on at

    Yes, you can use objects as parameters and change their internal state inside methods.

    If you meant something else, please rephrase your question.

  • Verified answer
    Joris dG Profile Picture
    17,782 on at

    X++ doesn't have reference parameters as such. However, Tables and Classes are implicit pointers so they are passed by reference automatically. Primitive types like int, str, etc. cannot be passed by reference, there is no support for that in X++.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Martin,

    What I mean is, in C#, everything is pretty much object, you can pass in method, set value, and get it outside of method.

    How about X++, like if I pass in a string or recid, can I do the same?

  • Ganriver1 Profile Picture
    1,559 on at

    Thanks

  • Martin Dráb Profile Picture
    240,061 Most Valuable Professional on at

    I really can't agree that value types in C#, such as int, are reference types. Boxing wan't  help you with to pass value types by reference; you need ref/out keywords to do that (as mentioned by Joris).

    X++ allow you to do that with CLR methods (byref keyword), but not with X++ methods.

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

    Hi Ganriver,

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans