X

New features in C# 7.0

Deep-dive posts to new features of C# 7.0: local functions, throw expressions, out variables, tuple literals, pattern matching in switch statements, ref returns and ref locals.

Local functions in C# 7.0

One of new features of C# 7.0 is support for local functions. Local functions are methods that are defined inside other methods to simplify more complex code and by example to support local recursion. This blog post shows how to use local functions in C# 7.0 and gives some advice in context of technical design of code.

Throw expressions in C# 7.0

C# 7.0 introduces throw expressions. We can add exception throwing to expression-bodied members, null-coalescing expressions and conditional expressions. This blog post introduces throw expressions, demonstrates how to use them and also provides a peek behind a compiled throw expressions.

Out variables in C# 7.0

C# 7.0 brings some features to out variables. These new features help us write cleaner code and handle out variables better. This blog post provides samples of these new features in C# 7.0 and as a surprise it also demonstrates what compiler is doing with these new features.

Tuple literals in C# 7.0

C# 7.0 brings some new features to tuples and with code editors that support these new features we can use tuples with named members instead of names like Item1…ItemN. This blog post goes through practical example that demonstrates how to move on classic method that returns multiple values to new tuples.

Internals of tuple literals

My last post about tuple literals gave brief intorduction to these. This post goes to internals of tuple literals, peeks behind the compiler and shows what happens with tuple literals internally. This post is for developers who are new to tuple literals and want to gain more deep understanding of these.

Pattern matching in switch statements

One of new features introduced by C# 7.0 is support for pattern matching in switch statements. It’s like mix of switch and if statements so we don’t have to nest these two. This blog post introduces pattern matching in switch statements and shows what C# compiler produces of switch statements.

Ref returns and ref locals in C# 7.0

C# 7.0 introduces ref returns and ref locals. Main goal of these new features is to make it easier for developers to pass around references to value types instead of copies of their values. This is important when working with large data structures that are implemented as value types. This blog post shows how to use ref returns and ref locals in Ć#.