Paul Krill
Editor at Large

Microsoft reveals new features in C# 7.0

news
Aug 26, 20162 mins

Version 7.0 offers tuples and pattern matching along with performance and coding improvements

road map travel salesman
Credit: Kate Ter Haar

Microsoft is fleshing out details this week of C# 7.0, a planned upgrade to its object-oriented language for the .Net Framework, emphasizing performance and code simplification.

Although C# 7.0 is still in development, most of the new features noted by Microsoft this week have been enabled in Visual Studio 15 Preview 4, released this week, said Mads Torgersen, Microsoft program manager for C#. “Perhaps the biggest features are tuples, which make it easy to have multiple results, and pattern matching, which simplifies code that is conditional on the shape of data.” Microsoft has mentioned these two features previously.

To handle tuples, a deconstruction declaration syntax enables developers to split a tuple or other value into its parts and assign these parts to fresh variables. C# 7 also features an out variables capability, for declaring a variable at the point where it is passed as an out argument.

Wildcards, a feature that is not confirmed for C# 7.0, would allow developers to ignore out parameters for which they have no use. The switch statement in version 7.0 is being extended so developers can switch on any type, not primitive types alone. The switch statement also will support patterns in case clauses, which can have additional conditions on them.

Literal improvements in the upgrade allow underscores to be used as digit separators inside number literals. “You can put them wherever you want between digits, to improve readability. They have no effect on the value,” said Torgersen. “Also, C# 7.0 introduces binary literals, so that you can specify bit patterns directly instead of having to know hexadecimal notation by heart.”

Generalized async return types are supported in the upgrade, expanding the number of types that can be returned from an async method. Expression bodied members capabilities have been expanded as well. “Expression bodied methods, properties etc. are a big hit in C# 6.0, but we didn’t allow them in all kinds of members. C# 7.0 adds accessors, constructors and finalizers to the list of things that can have expression bodies.” Additionally, a local functions capability in C# 7.0 lets developers take helper functions and declare them inside other function bodies.

Created by Anders Hejlsberg, who also led the charge in developing TypeScript, C# has significant traction among programmers. It ranks fourth in both the Tiobe and PyPL indexes of language popularity this month and fifth in RedMonk’s latest language rankings.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author