Mads on the Future of C# (6.0)

12/10/2013 6:37:01 PM

Mads on the Future of C# (6.0)

Mads Torgersen, head program manager of C#, presented the “Future of C#” at the NDC London conference on Friday morning 12/6. Most of the “probable” new features announced moved C# to a more succinct, functional programming style.

  1. Import type members into namespace.
  2. Succinct syntax for primary constructors.
  3. Readonly properties
  4. Property expressions (property lambdas)
  5. Method expressions
  6. Parameter arrays for IEnumerable interfaces
  7. Succinct null checking
  8. Multiple return values
  9. Constructor type inference

Mads provided a code demonstration of each new feature with before and after illustrations of how the code would be implement today versus the future. The code example below is taken from the presentation.

Embedded image permalink

using System;
using System.Text;
using System.Threading.Task;
// import types into namespace
using System.Math;

// primary constructor
public class Point(int x, int y)
    // readonly property
    public int X { get; } = x;
    public int Y { get; } = y;

    // property expressions
    public double Dist => Sqrt( X * X, Y * Y );

    // method expressions
    public Point Move(int dx, int dy) => new Point(X + dx, Y + dy);
    // parameter arrays for IEnumerable
    public static Point Avg(params IEnumerable<Point> points)
        // monadic null checking
        if (points?.FirstOrDefault()?.X ?? -1 )

    public void GetCoordinates(out int x, out int y) { x = X; y = Y; }

class Program
    static void Main(string[] args)
        var p = new Point(1, 5);

        // multiple return values
        p.GetCoordinates(out var x, out var y);

// constructor type parameter inference - 
var t = new Tuple(1,2); // infers Tuple<T1, T2>

The multiple return values features appears very tentative as some in the audience would prefer better syntax support for tuples. Mads took additional questions from the audience. Structural typing is “on the radar.” Mads would like to “get rid of FXCop” being a post-build process and “build in code contracts” instead of requiring a IL-rewriting step.







SoftPerson develops innovative new desktop software applications by incorporating artificial intelligence and natural language technologies to bring human-like intelligence to everyday applications.

Social Media