Visual Studio 2017 was released earlier this week with new programming language features for C# 7.0. C# is a type-safe, object-oriented programming language designed for building applications that run on the .NET framework. The Visual Studio team has been working on C# 7.0 for over a year.
“C# 7.0 adds a number of new features and brings a focus on data consumption, code simplification and performance. 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. But there are many other features big and small. We hope that they all combine to make your code more efficient and clear, and you more happy and productive,” Mads Torgersen, program manager at Microsoft, wrote in a post.
The latest version of the programming language adds out variables in order to declare a variable instantly. Before, it wasn’t possible to use out parameters fluidly, Torgersen explained.
C# 7.0 also introduces patterns such as constant patterns, type patterns, and var patterns. Torgersen says this is a new language element for C# design to test a certain shape of a variable and extra information. The company is also adding is experiences and case clauses to to enhance the pattern experience. Is expressions allow developers to have patterns on the right-hand side, while case clauses allow switch statements to match on patterns.
The language’s tuple types and tuple literals are designed to enable developers to return more than one value from a method. “Tuples are value types, and their elements are simply public, mutable fields. They have value equality, meaning that two tuples are equal (and have the same hash code) if all their elements are pairwise equal (and have the same hash code),” Torgersen wrote. “This makes tuples useful for many other situations beyond multiple return values. For instance, if you need a dictionary with multiple keys, use a tuple as your key and everything works out right. If you need a list with multiple values at each position, use a tuple, and searching the list etc. will work correctly.”
Other features include: local functions, deconstruction declaration, literal improvements, ref returns and locals, generalized async return types, more expression bodied members, and throw expressions.