What’s new in C# 7.1, 7.2 & 7.3 and what’s next

, 3 minutes to read

C# is con­tin­u­ously evolv­ing and ab­sorb­ing many use­ful fea­tures. Some of them are syn­tax sugar and Vi­sual Stu­dio will pro­pose a sim­pli­fied code, but some of them al­lows what wasn’t pos­si­ble be­fore so tak­ing ad­van­tage of new C# ver­sion re­quires a change of think­ing about the code. The best way how to un­lock new ca­pa­bil­i­ties is learning of func­tional pro­gram­ming be­cause most fea­tures are taken from F#.

The biggest tech­ni­cal change is De­fault in­ter­face mem­bers be­cause it re­quires a change in .NET run­time which is what haven’t been done since the in­tro­duc­tion of gener­ics in .NET 2.0. It will al­low to add a new mem­ber to the in­ter­face if you pro­vide a map­ping to one of ex­ist­ing mem­bers.

The most sig­nif­i­cant per­for­mance im­prove­ment was made by in­tro­duc­tion of Span which is an ar­ray of poin­t­ers to an­other ar­ray. The string.Sub­string method is in­ef­fi­cient be­cause it re­turns a copy if the orig­i­nal string. It is much more ef­fi­cient to re­turn a win­dow to the orig­i­nal string without need to copy any­thing.

The most use­ful change for con­sumers is some­thing what can re­duce a chance of Null­Ref­er­ence­Ex­cep­tion in pro­duc­tion code. De­vel­oper can opt-in for non-nul­lable ref­er­ence types which means that is no longer pos­si­ble to as­sign null into poin­ter (string is a poin­ter). Nulls will be al­lowed only in nul­lable types (like string?).

“I think I’ve of­ten cried be­fore. If I had to do over I would sep­arate nul­la­bil­ity from value ver­sus ref­er­ence rep­re­sen­ta­tion of types such that you could have non-nul­lable ref­er­ence types which is the one thing we don’t have to­day. The abil­ity to say: this string can never be null. You, com­piler, warn me if I made a mis­take such that I can ever find a null.” – An­ders He­jls­berg, lead ar­chi­tect of C#, May 2011, Chan­nel 9

C# 7.1

C# 7.2

C# 7.3

C# nullable reference types preview

C# patterns and ranges preview

C# 8.0 proposals