TryParse with out var param

A new feature in C# 6.0 allows to declare variable inside TryParse method. Declaration expressions was cut from C# 6.0 and wasn’t shipped in the final release. You currently can’t do that. There is a proposal for it on GitHub for C# 7 (also see this for future reference). Update (07/03/2017) With the official release … Read more

Automated property with getter only, can be set, why?

This is a new C# 6 feature, “Getter-only auto-properties”, also known as “Auto-Property Initializers for Read-Only Properties” as discussed in this MSDN magazine article ‘C# : The New and Improved C# 6.0’ by Mark Michaelis and in the C# 6.0 draft Language Specification. The read-only field’s setter is only accessible in the constructor, in all … Read more

How to upgrade msbuild to C# 6?

Make sure you call: C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe That’s the version of MsBuild that ships with Visual Studio 2015 and calls the C# compiler that understands this. You can get this version of MsBuild on your system by installing any edition of Visual Studio 2015 or by installing the stand-alone Microsoft Build Tools 2015. Adding a … Read more

Lambda for getter and setter of property

First of all, that is not lambda, although syntax is similar. It is called “expression-bodied members”. They are similar to lambdas, but still fundamentally different. Obviously they can’t capture local variables like lambdas do. Also, unlike lambdas, they are accessible via their name:) You will probably understand this better if you try to pass an … Read more

Why can’t I use the null propagation operator in lambda expressions?

It’s complicated since expression tree lambdas (unlike delegate lambdas) are interpreted by already existing LINQ providers which don’t yet support null propagating. Converting to a conditional expression is not always accurate as there are multiple evaluations while with ?. there’s only a single evaluation for example: customer.Where(a => c.Increment()?.Name) // Written by the user customer.Where(a … Read more

Is nameof() evaluated at compile-time?

Yes. nameof() is evaluated at compile-time. Looking at the latest version of the specs: The nameof expression is a constant. In all cases, nameof(…) is evaluated at compile-time to produce a string. Its argument is not evaluated at runtime, and is considered unreachable code (however it does not emit an “unreachable code” warning). From nameof … Read more

How do I disable C# 6 Support in Visual Studio 2015?

You can set the language feature for each project separately by going to Properties => Build tab => Advanced button => Language Version and set your preferred version. You should realize that it will still use the new “C# 6.0” .Net Compiler Platform (codenamed Roslyn). However, that compiler will imitate the behavior of older compilers … Read more

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