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)

passing reference parameter to method

(0) ShareShare
ReportReport
Posted on by 1,559

Hi Friends,

in AX, there is no ref parameter like other language, what's alternative then? If I need to pass something to method, and get updated value back.

 

Thanks,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nunomaia Profile Picture
    25 Moderator on at

    I don't think there is an equivalent as in C#.  You can only use out parameters with .NET interoperability.  You need to return multiple parameters from a method, you could use a container for that.

  • Verified answer
    5400 Profile Picture
    7,162 on at

    You can use static method as single return or multiple return (Container)

    Ref: class-> DMFgenerateSSISPackage ->GenerateStagingData

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Guys, please, start thinking in objects...

    Create an object and safe a reference to a variable. Pass the object to the method, let it modify there and then just access it in the caller method and read the modified state.

    When you pass an object, you're really passing just a reference to memory where the object resides. Therefore all references point to the same object and all see any changes you make to it.

  • Ganriver1 Profile Picture
    1,559 on at

    Martin,

    are you talking about class? or Container is also considered as object.

  • Suggested answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Classes are object definitions (which instance methods it has, which instance variables etc.). Objects are concrete instances of classes (with specific variable values etc.) saved somewhere in memory.

    Container is a value type, not a reference type (= not an object). If you looked into documentation, you would find it very explicit:

    In X++, container is one of the primitive types, or value types. container is not a class. A container contains an ordered sequence of primitive values or other containers.

    Learning the basics of X++ and object-oriented programming would be very wise.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Martin,

    I just want to return a simple integer from method, using class seems to me is overkill.

    Also, as others said, using Container to do it, is this something like boxing/unboxing in X+?

  • 5400 Profile Picture
    7,162 on at

    It is very simple please create your method return type integer and return the value. I don't know, I am missing anything or not.

  • Ganriver1 Profile Picture
    1,559 on at

    Hi Bhaskar,

    This is not what I want. Just need to pass parameter.

  • 5400 Profile Picture
    7,162 on at

    could I get more inside end to end.

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    If you "want to return a simple integer from method", just return the integer at the return value, as Bhaskar Roy suggested.

    If you want to return a reference, use a reference type, as I suggested. Whether you consider it as a overkill or not is irrelevant.

    Boxing/unboxing wouldn't help you in any way.

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