Just Young Is C# 6, And Here Comes C#7! What is New in C# 7 and What To Expect?

It has not been long since C# 6 release with a few useful improvements, and here comes C# 7 – excited yet?! Watch your recliner and read on:

Tuples
I have not used that much so please go ahead and comment your thoughts. These are going from reference type to value type. It appears simple syntax is taking on again:


var result = (5, 20);
var result = (count: 5, sum: 20);

https://msdn.microsoft.com/en-us/library/system.tuple

Multi-Value Returns From Functions/Methods

This is quite a feast (let’s consume that all together while drooling) for getting out out of parameters. I'm sure I'm note the only one who wanted to return multiple values from a method. Presumably, you'll be able to have code that looks like this:


(x, y, z) = new Foo().Boo();
...
public class Foo {
...
public (int x, string y, SomeClass z) Boo()
{
...
}

That look beautiful yet?

Next, following the case in switches, looks like there is a freedom of deciding when. Say,


switch (object value)
{
case int value when value == 0:
// do something
case string value when value == "n/a":
// do something else
}

There is quite some more changes that I don't feel comfortable talking about as I don't have enough experience with those, but C# 7 looks like a good overheaul and great improvements!
Sound your thoughts in the comments!

This entry was posted in C# and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *