Wednesday, April 15, 2015

X++ Method parameters actually pass by value or reference?

Good morning everyone. This is just a short note. I've seen a code which update/change the value of a parameter variable.(see below) This make me very confuse because as far as I knew normally X++ parameters are passed by value.

void test(EcoResProductMaster _EcoResProductMaster = null)
{
    ;

    EcoResProductMaster.data(_EcoResProductMaster);

    this.aaa();
    this.bbb();
    this.ccc();

    _EcoResProductMaster.data(EcoResProductMaster);


I googled and then I found the following useful link.

So there are two base types in X++ which are passed by reference. They are record and class.

String Assigned and passed by VALUE
Integer Assigned and passed by VALUE
Real Assigned and passed by VALUE
Date Assigned and passed by VALUE
Enum Assigned and passed by VALUE
Container Assigned and passed by VALUE
Record Assigned and passed by REFERENCE
Class instance (any object instanciated with ‘new()‘) Assigned and passed by REFERENCE
AnyType Assigned and passed by VALUE, even when holding a Record or Class instance
Guid Assigned and passed by VALUE
Int64 Assigned and passed by VALUE

Hope that helps, enjoy your day.

No comments:

Post a Comment