Skip to main content

Notifications

Microsoft Dynamics AX forum

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

Posted on by 1,531

Hi Friends,

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

Thanks,

*This post is locked for comments

  • Suggested answer
    Hossein.K Profile Picture
    Hossein.K 6,642 on at
    RE: X++ method parameter can be reference object, and return value

    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

  • Martin Dráb Profile Picture
    Martin Dráb 229,133 Most Valuable Professional on at
    RE: X++ method parameter can be reference object, and return value

    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.

  • Ganriver1 Profile Picture
    Ganriver1 1,531 on at
    RE: X++ method parameter can be reference object, and return value

    Thanks

  • Ganriver1 Profile Picture
    Ganriver1 1,531 on at
    RE: X++ method parameter can be reference object, and return value

    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?

  • Verified answer
    Joris dG Profile Picture
    Joris dG 17,775 on at
    RE: X++ method parameter can be reference object, and return value

    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++.

  • Martin Dráb Profile Picture
    Martin Dráb 229,133 Most Valuable Professional on at
    RE: X++ method parameter can be reference object, and return value

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

    If you meant something else, please rephrase your question.

  • Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: X++ method parameter can be reference object, and return value

    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

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

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,802 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,133 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,154

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans