Greg Reddick is a noted speaker, author, and software engineer. This blog covers all aspects of programming, particularly for Windows, and other related topics.

2015-09-08

New Features in C# Version 7

I previously commented on the features being developed for C# version 6, shipped with Visual Studio 2015. They are now working on C# version 7. The discussion can be followed at https://github.com/dotnet/roslyn/labels/Design%20Notes. Right now they are just talking about things, and nothing is set in stone.

The tuples feature would allow a method to return multiple values, among other things. The LUA language has this ability, and I find it rather nice.

Pattern matching would have some syntax similar to a switch statement that could match a string to a pattern and execute some code.

Records would simplify having a simple type essentially only made of properties.

Nullability tracking would allow you to specify whether a reference variable would ever be allowed to be null. For example, you could make a string variable that could never be null. It sounds like this would be implemented as a language feature, not a CLR (common language runtime) feature, so under some circumstances it could be defeated. I'm unsure whether implementing this halfway is the right thing to do here.

Method contracts would move code contracts into the language. This would be welcome feature, as now they are implemented as method calls and a tool that patches the C# code.

Readonly parameters and locals. This would improve code quality. I'm not sure I like the keywords they are talking about, but the feature is good.

Immutable types. Another thing to improve code quality.

Array slices. There is one place in my code that this would improve performance by several orders of magnitude. They are saying that this would require CLR support, so is unlikely to make it into version 7.

Local functions. Syntactic sugar, don't think it is really that helpful.

Some nice things. I do worry that they are making the language more complicated with each version. This increases the learning curve for new programmers.