Return multiple values from a C# asynchronous method

After playing with the code I was able to figure it out. Here is the solution. public async Task DeleteSchoolTask(int schoolNumber, int taskDetailId) { var result = await GetTaskTypeAndId(taskDetailId); int taskId = result.Item1; string taskType = result.Item2; // step 1: delete attachment physically from server var fileService = new FileService(Logger, CurrentUser); var relativeFilePath = $”{schoolNumber}\\{Consts.RM_SCHOOL}\\{taskDetailId}”; … Read more

Using a C# 7 tuple in an ASP.NET Core Web API Controller

It doesn’t work because named tuple names are not quite “real”, it’s mostly syntax sugar provided by compiler. If you look at ValueTuple set of types, by which named tuples are represented, you will see that they have properties like Item1, Item2 and so on. Compiler will rewrite all your references to named tuple names … Read more

How to declare a C# Record Type?

Update: C# 9 now contains record types. public record Person { public string LastName { get; } public string FirstName { get; } public Person(string first, string last) => (FirstName, LastName) = (first, last); } Old answer: Record types are not (yet) implemented in C#. See the proposal in the official GitHub repository: https://github.com/dotnet/csharplang/blob/master/proposals/records.md Discuss … Read more

C# 7.0 ValueTuples vs Anonymous Types

Anonymous types are immutable, ValueTuples are not. This is reflected in the fact that anonymous types expose properties, ValueTuples expose fields. Data binding almost always requires properties. Plenty of existing code only works with reference types, not with value types. What in particular comes to mind are projections in Entity Framework: projections to value types … Read more

Name ValueTuple properties when creating with new

No, you can’t. The ValueTuple types are actually independent of the named field support in C#. The latter works more like named properties for anonymous types. That is, the compiler analyzes the code and generates aliases to the appropriate members according to your declarations and usages. It is through the assignment that the compiler learns … Read more

C# 7 Expression Bodied Constructors

A way to do this is to use a tuple and a deconstruction to allow multiple assignments in one expression: public class Person { public string Name { get; } public int Age { get; } public Person(string name, int age) => (Name, Age) = (name, age); } As of C# 7.1 (introduced with Visual … Read more

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