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)

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,438 User Group Leader 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
    237,939 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,775 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
    237,939 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,648 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

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans