Getting “Tuple element name is inferred. Please use language version 7.1 or greater to access an element by its inferred name.”
Project->Properties->Build->Advanced->Language Version->C# latest Minor Version
Project->Properties->Build->Advanced->Language Version->C# latest Minor Version
Step 1: add the ValueTuple nuget package to your project. Step 2: as Lucas says in his comment, change the syntax to: private async Task<(SomeArray[], AnotherArray[], decimal)>GetInvoiceDetailAsync( InvoiceHead invoiceHead) { … return (x, y, z); } Note though that you can also then add names to those tuple items, along the lines of: private async … Read more
You do NOT need to target .NET 4.6 and above, that is incorrect. To use Tuples, you need the System.ValueTuple NuGet package. Right on https://www.nuget.org/packages/System.ValueTuple/ you can see it says it supports 4.5 and above, and actually, it supports 4.0 and above. And if you want to get crazy, if you create your own System.ValueTuple … Read more
I was able to resolve this by installing the Microsoft.Net.Compilers nuget package for v2.0.0-rc3, the only version installed prior was 1.3.2. I still don’t understand why the intellisense and compiler errors would show up if the installed compiler didn’t support this.
You can shorten it to: void test( Action<ValueTuple<string, int>> fn) { fn((“hello”, 10)); } test(((string s, int i) t) => { Console.WriteLine(t.s); Console.WriteLine(t.i); }); Hopefully, one day we might be able to splat the parameters from a tuple to the method invocation: void test(Action<ValueTuple<string, int>> fn) { fn(@(“hello”, 10)); // <– made up syntax } … Read more
For arbitrary task-like types you linked to in the 2nd part of your question you need to include the System.Threading.Tasks.Extensions package. The reason you need these NuGet packages is because the new language features rely on new types added to the .NET framework. The new types that the C# language features depend on will not … Read more
In website’s NuGet window: Uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform Re-install it In web.config, under: system.codedom > compilers > compiler, change compilerOptions=”/langversion:6 to 7
The discards are basically a way to intentionally ignore local variables which are irrelevant for the purposes of the code being produced. It’s like when you call a method that returns a value but, since you are interested only in the underlying operations it performs, you don’t assign its output to a local variable defined … Read more
Let’s go through the features new in C# 7.0: Tuples: The System.ValueTuple package has a version for the portable-net40+sl4+win8+wp8 profile. That means it is usable on .Net 4.0. (Not sure why dependencies list only .Net 4.5.) If you wanted to use tuples on even lower versions of .Net, it should still work, as long as … Read more
Value tuples are value types. They can’t be null, which is why the compiler complains. The old Tuple type was a reference type The result of FirstOrDefault() in this case will be a default instance of an ValueTuple<int,int,int> – all fields will be set to their default value, 0. If you want to check for … Read more