📜 ⬆️ ⬇️

Bug in Visual Studio 2017 RC using new C # 7 features

Many of you, those from the .NET world, probably already know that not so long ago (a month ago) Microsoft released Visual Studio 2017 RC, complete with which of course goes C # 7. What is called to the court of enthusiasts. Studying the possibilities of the new version, I suddenly dropped Visual Studio. How - read under the cut.

So, to play the bug you need Visual Studio 2017 RC . Next, create a console application and paste this straightforward code:

class Program { class IwillCrash { public void Deconstruct(out int x) { x = 0; } } static void Main(string[] args) { //var (x) = new IwillCrash(); // BOOM! deconstruction feature crashes VS2017 RC } } 

For those who do not understand the code, let's see what it means. Here are used such innovations as C # 7:

- Tuples - tuples
- Deconstruction - and translated
Tuples, let's say, regular syntactic sugar of the language.
')
It used to be:

 Tuple<int, string> MyFunc(Tuple<decimal, long> param) 

Now you can:

 (int, string) MyFunc( (decimal, long) param ) 

Note that to use this feature, you must install the System.ValueTuple assembly.
Install-Package "System.ValueTuple" -IncludePrerelease

Deconstruction, or more precisely, deconstruction-declaration or destructive declaration (deconstructing declaration) is the ability to parse a tuple into variables, while defining them.

For example:

 (string first, string middle, string last) = LookupName(id1); 

Where the method is declared as follows:

 (string, string, string) LookupName(long id) 

The result of the construction above will be the declaration of three new variables: first, middle, last, which will return the LookupName method as a tuple. In other words, the tuple is split into three variables.

The destructive declaration applies not only to tuples, but also to user classes. One condition is the definition of a deconstructor called Deconstruct. As in the example above. This feature allows you to split the class object into its component parts.

Example:

 class Point { public void Deconstruct(out int x, out int y) { x = 1; y = 2; } } (var myX, var myY) = new Point(); //  Deconstruct(out myX, out myY); 

As you understand, as a result, we will have myX = 1, myY = 2 .

It seems all sorted out. Now inhale and uncomment the code at the beginning of the post.

image The trick was a success - the studio was gone, the testers were probably fired, and with a single ticket in the dashboard of the studio developers it became more.

Although, in fairness, for .NET Core this code works. Maybe this is such a clever idea?
The release should be fixed, as the report was sent to the bug before the post.

→ A good description of the new features of C # 7 can be found here (eng.)

UPD: At the request of Habrayuser Varim in the comments, I still found a place where Microsoft keeps a list of known bugs in Visual Studio. The bug described in the post is here .

Source: https://habr.com/ru/post/317804/


All Articles