Today I attended an excellent TechTalk on C# 7.0 by Mads Torgersen at a full house in Microsoft Development Center Copenhagen.

 

As the talk unfolded I was struck by Déjà vu– this is not the first time I've heard Mads present a new feature in C#, that I've been using for a long time. Last time it resulted in two blog posts:

 

This time Mads presented a handful of new features, 3 of which X++ already has. Granted, the X++ variants of these are not as powerful, and not as complete. Yet, the intentions are the same:

  1. Inline functions
  2. Multiple return values from a method
  3. Deconstruction

 

Here are two implementations using these capabilities – one is X++ one is C#. Can you spot which is which?

public void foo() 
{  

    var arr = new int[] {4, 8, 15, 16, 23, 42};  
    int s, c;  
    (s, c) = this.tally(arr);
}
private (intint) tally(int[] arr) 
{  
    int c, s;  
    void add(int v) 
    {  
        c++;  
        s+=v;  
    }  
    foreach(var v in arr) 
    {  
        add(v);  
    }  
    return (s, c);  
}  

public void foo() 
{  
    var arr = [4, 8, 15, 16, 23, 42];  
    int s, c;  
    [s, c] = this.tally(arr);  
}  

private container tally(container arr) 
{  
    int c, s;  
    void add(int v) 
    {  
        c++;  
        s+=v;  
    }  
    for (int i = 1; i <= conlen(arr); i++) 
    {  
        add(conpeek(arr, i));  
    }  
    return [s, c];  
}  

 

As you may have read in my series of blog posts on X++ in AX7, it is obvious that X++ is moving in the direction of C# - seeing C# moving in the direction of X++ is not something I had seen coming – but it is very welcome!