C#7 tuple & async

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

In C# 7 is it possible to deconstruct tuples as method arguments

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

How can I enable all features of C# 7 in Visual Studio 2017 project?

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

Discard feature significance in C# 7.0?

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

Does C# 7.0 work for .NET 4.5?

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

How to null check c# 7 tuple in LINQ query?

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)