C# 7 added Tuples and provides an awesome syntax for accessing them. C# 7.1 improved the usability of tuples further with Tuple Name Inference. However, sometimes you need to access them dynamically and this can be tricky.
Visual Studio 2017.3 brought with it the first minor update to the C# language, C# 7.1. This update adds four new features to C#: async main, target-typed default literals, tuple name inference, and generic support for pattern-matching.
In this post, you'll learn how to enable the new C# 7.1 language features in your …Read More
Casting to generic interfaces that use covariance or contravariance is two orders of magnitude slower than normal casts in C#. This means casting to
IEnumerable<T> is two orders of magnitude slower too. This result was quite unexpected and very surprising.
In this post, I investigate the cost of casting to implementations, interfaces, generic interfaces, covariant …Read More
C# has long supported two operators to check the type of an object:
as. C# 7 adds a new way to use the
is operator that combines
is with basic patterns to provide an alternative for
is patterns provide a nicer syntax for safe casting than both the existing
C# has always supported the ability to pass by reference using the
ref keyword on method parameters. C# 7 adds the ability to return by reference and to store references in local variables.
The primary reason for using ref returns and ref locals is performance. If you have big structs, you can now reference these directly in safe code to avoid copying. Before C# 7 you had …Read More
Local functions in C# 7 are versatile: they can be passed as
Action<> to other methods and they can be defined using the inline expression bodied syntax.
Because local functions are compiled into static methods, you should be able to pass them to any method that requires a
Action<> and sure …
One of the new language features in C# 7 is local functions. This feature lets you define functions within the scope of other functions. The main benefit of local functions is encapsulation and a secondary benefit is that they bring local variables into scope.
Although local functions appear simple, their interaction with other language features quickly leads to questions. I wondered …Read More