Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New tuple syntax not working in C# version 7

I've started trying new features of C# 7 in Visual Studio Enterprise 15 Preview 2. I'm able to run code of other upcoming features like Binary literals, digit separators etc. But the new syntax of initialization of tuples is not working.

Here is my code snippet:

var latLong = new (double lat, double lng) { lat = 0, lng = 0 };
var result = (5, 20);
var result = (count: 5, sum: 20);

I've followed all the steps mentioned in this blog. Just posting this question if anyone else has also come across this issue. Above code results in compilation failures as shown below:

1>Program.cs(18,26,18,27): error CS1031: Type expected
1>Program.cs(18,27,18,33): error CS1525: Invalid expression term 'double'
1>Program.cs(18,34,18,37): error CS1003: Syntax error, ',' expected
1>Program.cs(18,39,18,45): error CS1525: Invalid expression term 'double'
1>Program.cs(18,46,18,49): error CS1003: Syntax error, ',' expected
like image 822
RBT Avatar asked Feb 06 '23 20:02

RBT


1 Answers

I was able to figure this out from another link here. If you read through the comments section it is evident that not all new upcoming features of C# have been able to make it to last VS 15 release which was published. Tuple (value types with new declaration syntax) is one such feature.

We might have to wait for RTM build before all features can really start working OR the other way is to get the latest source code of roslyn from its gitHub repository, clone it on your own machine, compile it and make your Visual Studio 15 Preview 2 installation to use it. More latest commit you pull, more features you will get to play with.

like image 165
RBT Avatar answered Feb 16 '23 00:02

RBT