Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuple syntax in VS 2017

Tags:

In VS2017 RC, when you tried to use new tuple syntax, you received the following error:

CS8179 Predefined type 'System.ValueTuple`X' is not defined or imported

In order to use tuple syntax, you had to manually import ValueTuple nuget package into the project. Not a big deal, as it was pre-release version and I thought it will be changed in RTM so it will be enabled by default. Unfortunately in the final release version it is still the case and you have to download nuget package for every single project to use tuple syntax.

Is there a way to have tuple syntax enabled for every project by default?

like image 479
user3126358 Avatar asked Mar 07 '17 20:03

user3126358


People also ask

What is tuple in Visual Basic?

A tuple is a lightweight data structure that has a specific number and sequence of values. When you instantiate the tuple, you define the number and the data type of each value (or element). For example, a 2-tuple (or pair) has two elements. The first might be a Boolean value, while the second is a String .

How do you do a tuple in Python?

Creating a Tuple A tuple in Python can be created by enclosing all the comma-separated elements inside the parenthesis (). Elements of the tuple are immutable and ordered. It allows duplicate values and can have any number of elements. You can even create an empty tuple.

How do you access tuple elements in F#?

In F#, tuples provide built-in functions. You can access first element by using fst () and second element by using snd () function.

Can a tuple have 3 items?

A tuple is a data structure that has a specific number and sequence of values. The Tuple<T1,T2,T3> class represents a 3-tuple, or triple, which is a tuple that has three components. You can instantiate a Tuple<T1,T2,T3> object by calling either the Tuple<T1,T2,T3> constructor or the static Tuple.


1 Answers

According to https://github.com/dotnet/roslyn/issues/13177, the ITuple and ValueTuple types will be added to mscorlib in "the first version after" .NET Framework 4.7. According to the .NET Framework 4.7 release notes, it has been added. Adding it to 4.6.x would break semver. Hence they provided the types as a Nuget package so that projects based on older framework versions can use it.

This is akin to a .NET 2.0 project wanting to use LINQ which the extension methods lived in System.Core, not mscorlib.

One option you could do is create your own project templates in the interim that reference the NuGet package.

like image 114
Daniel A. White Avatar answered Sep 19 '22 18:09

Daniel A. White