Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X++ switch case with multiple inputs

Tags:

axapta

x++

Is there a way like in C# to create a switch with multiple variables? something like this..

 switch((_dim1,_dim2,_dim3))
 {
        case(1, ""):
            Info("1 is null");
        case (2, ""):
            Info("2 is null");
        case (3, ""):
        break;
 }
like image 965
Tweene Avatar asked Oct 20 '25 19:10

Tweene


1 Answers

Switch with multiple arguments have been possible since version 1.0 (+23 years). It requires the use of containers. There is no dont-care value.

The following job demonstrates:

static void TestConSwitch(Args _args)
{
    int dim1 = 2;
    str dim2 = '';    
    switch ([dim1, dim2])
    {
        case [1, '']:
            info("Case 1");
            break;        
        case [2, '']:
            info("Case 2");
            break;
        default:
            info("Default!");
    }
}

In this case displays "Case 2".

That said, performance of this may not be great, as it requires the build of containers for both the target value and all the case values (if no match). Looks kind of neat though.

like image 160
Jan B. Kjeldsen Avatar answered Oct 23 '25 18:10

Jan B. Kjeldsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!