What is the idiomatic naming convention for local functions in C# 7 [closed]

My standard is always PascalCase, also spell out the full word. I don’t like abbreviations as they can have multiple meanings. So, in your PascalCase scenario, I would spell out the ‘Calc’ word to be the following: public static int Factorial(int n) { return CalculateFactorial(n); int CalculateFactorial(int number) => (number < 2) ? 1 : … Read more

In C#7, how can I “roll my own” Task-like type to use with async?

I couldn’t find any good tutorial yet. But you can look at the compiler unittests which create such task-like types (look for “[AsyncMethodBuilder”). The starting point is to create a type and mark it as task-like with an attribute like [AsyncMethodBuilder(typeof(MyTaskBuilder))]. Then you need to define your own MyTaskBuilder type. It must implement a certain … Read more

Convert anonymous type to new C# 7 tuple type

Of course, by creating the tuple from your LINQ expression: public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => (o.Id,o.Name)) .First(); return obj; } According to another answer regarding pre-C# 7 tuples, you can use AsEnumerable() to prevent EF to mix things up. (I have not much experience with EF, but … Read more

C# 7 local function not working as expected and no errors being displayed

You need to update nuget package named “Microsoft.Net.Compilers” to the latest version. Most likely you have version 1.3.2 installed in your project but you need 2.0.1 to use C# 7 features. Alternatively – you can remove this package at all (together with packages that depend on it) – then it will also work, because it … Read more

Expression of type T cannot be handled by a pattern of type X

As explained by Neal Gafter from Microsoft: The reason it doesn’t work is that there is no conversion (explicit or implicit) defined from T to KeepalivePacket. Pattern matching requires such a conversion to exist, as it is defined in terms of the cast operator, which requires a conversion exist. The language specification and compiler agree … Read more

How to create a List of ValueTuple?

You are looking for a syntax like this: List<(int, string)> list = new List<(int, string)>(); list.Add((3, “first”)); list.Add((6, “second”)); You can use like that in your case: List<(int, string)> Method() => new List<(int, string)> { (3, “first”), (6, “second”) }; You can also name the values before returning: List<(int Foo, string Bar)> Method() => … … Read more

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