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.
This story, "Microsoft reveals new features in C# 7.0" was originally published by InfoWorld.