.NET Framework - What's New in C# 7.0

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
An exploration of the new features due in C# 7.0

  • Deconstructors
  • Tuples
  • Pattern Matching
  • Local Functions
  • Return by Reference
  • Out Variables
  • Literal Improvements
  • Generalized Async Return Types
  • Expression-Bodied Members for Constructors, Accessors, Finalizers
  • Throw Expressions

Nice to see Tuples and Pattern Matching, these two alone will be hugely transformative; removing quite a bit of boilerplate. Still missing a lot though, for example: complex value types, value type indirection, higher kinded polymorphism, ...

Article reference: https://msdn.microsoft.com/magazine/mt790184
Article code: https://github.com/IntelliTect-Samples/2016.11-ProgrammingCSharp7
Original C# Design Article: https://msdn.microsoft.com/magazine/mt595758
 

Spacerat

Expert Member
Joined
Jul 29, 2015
Messages
1,328
Yes I love the ability to use Tuples as return variable to return multiple values. Never liked the 'out' pattern. Although that is now also streamlined. Wonder if out is actually still needed?
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Yes I love the ability to use Tuples as return variable to return multiple values. Never liked the 'out' pattern. Although that is now also streamlined. Wonder if out is actually still needed?
Their chosen syntacic sugar for tuples is perfect, aligns well with another languages. Really hope this becomes a trend in C#, less verbosity and more sugar. 'out' pattern usage is very much a personal choice / paradigm thing; personally I try to avoid reference passing and mutability.

The other thing I love them to add (aside from many others) is operator overloading (adhoc polymorphism).
 

_kabal_

Executive Member
Joined
Oct 24, 2005
Messages
5,922
I do a little bit of C# as part of a corporate consulting gig.

Nothing like TFS telling you that you broke the build, because you mistakenly used C# 6.0 language features :mad:
 

Pakka

Expert Member
Joined
Jul 22, 2010
Messages
2,271
I do a little bit of C# as part of a corporate consulting gig.

Nothing like TFS telling you that you broke the build, because you mistakenly used C# 6.0 language features :mad:

This. And when not all devs are on the latest Visual Studio
 

semaphore

Honorary Master
Joined
Nov 13, 2007
Messages
15,199
[)roi(];18691472 said:
The other thing I love them to add (aside from many others) is operator overloading (adhoc polymorphism).

You can already do operator overloading :confused:, albeit on user defined types.
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
You can already do operator overloading :confused:, albeit on user defined types.
Probably should have clarified bit more -- yeah common mistake of being too brief when verbosity is probably required. So let me add some:
  • it's really more about how MS's has implemented adhoc polymorphism of which operator overloading is one of the more prescient applications. F# as example doesn't have this limitation.

So focusing in on the current C# implementation; currently it's a limited class based solution, for example:
  • Operators can't behave like any other stdlib function, or more specifically C# like Java tends to treat functions as just another part of a class as opposed to independent "objects". This lack of global functions i.e. outside of class existence is much of the limitation.
  • Precedence rules are always predefined; and always have to link back to built-ins -- which explains the lack of a wider a character set for operators. Not that I'm wanting to make + behave any different than what everyone's used to, but rather that I like to define a custom operator that has precedence ahead of something else, even one of the built-ins.
  • Coupled with general polymorphism (generics); C# doesn't yet support function extensibility that covers more than a single class e.g. extensibility of interfaces and all the objects associated with that interface. For example: 1 global generic operator overload vs. 1 per class. How does this help? Basically every type that implements the interface gets the more "globally" defined operator overload, simply though conformance.

The problem is arguably greater than just operator overloading, but that's a pattern I employ quite often i.e. global operator or interface / protocol extension operators for combining dissimilar types. Really strips out a lot of usage complexity; syntactically easier, making the code far more declarative. Extra plus points, is that it strips out a lot of boiler plate.

Hope that helps clarify the confusion?
 
Last edited:

etienne_marais

Honorary Master
Joined
Mar 16, 2008
Messages
15,093
Which .net framework versions does C#7 support?

From the lack of information available on the internet (one would presume an explicit reference to it), I'm assuming that CLR 4.0 would be adequate, thus .NET 4.0 or later. I'm assuming this because we are not talking about an extended API, but language features which would require an IDE/Compiler update to compile as opposed to a new CLR to handle it (AFAIK the new language features could possibly be implemented at MSIL/bytecode level without changes to the CLR).

This Blog gives the impression that the IDE/Compiler features needed for most C# 7 features are available in Visual Studio 2015 Preview 4 (released August 22, 2016)
 
Top