Dajbych.net


What’s New in C# 7.1, 7.2 & 7.3 and What’s Next

, 2 minutes to read

net2015 logo

C# is continuously evolving and absorbing many useful features. Some of them are syntactic sugar, and Visual Studio will propose simplified code, but some of them allow what wasn’t possible before, so taking advantage of the new C# version requires a change in thinking about the code. The best way to unlock new capabilities is by learning functional programming because most features are taken from F#.

The biggest technical change is Default interface members because it requires a change in the .NET runtime, which hasn’t been done since the introduction of generics in .NET 2.0. It will allow adding a new member to the interface if you provide a mapping to one of the existing members.

The most significant performance improvement was made by the introduction of Span, which is an array of pointers to another array. The string.Substring method is inefficient because it returns a copy of the original string. It is much more efficient to return a window to the original string without needing to copy anything.

The most useful change for consumers is something that can reduce the chance of a NullReferenceException in production code. Developers can opt-in for non-nullable reference types, which means that it is no longer possible to assign null to a pointer (string is a pointer). Nulls will be allowed only in nullable types (like string?).

“I think I’ve often cried before. If I had to do over I would separate nullability from value versus reference representation of types such that you could have non-nullable reference types which is the one thing we don’t have today. The ability to say: this string can never be null. You, compiler, warn me if I made a mistake such that I can ever find a null.” – Anders Hejlsberg, lead architect of C#, May 2011, Channel 9

C# 7.1

C# 7.2

C# 7.3

C# nullable reference types preview

C# patterns and ranges preview

C# 8.0 proposals