C# 6.0 Features Not Working with Visual Studio 2015

This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package CodeDOM Providers for .NET Compiler… Replacement CodeDOM providers that use the new .NET Compiler Platform (“Roslyn”) compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as … Read more

How to use C# 6 with Web Site project type?

I’ve tested this with ASP.NET MVC 5 (tested 5.2.3), and your mileage may vary with other web frameworks, but you just need to add the NuGet package for Roslyn CodeDOM. Microsoft.CodeDom.Providers.DotNetCompilerPlatform should add the DLL files… PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform Replacement CodeDOM providers that use the new .NET Compiler Platform (“Roslyn”) compiler as a service APIs. … Read more

How do I use the C#6 “Using static” feature?

It appears the syntax has slightly changed since those blog posts were written. As the error message suggests, add static to your include statement: using static System.Console; // ^ class Program { static void Main() { WriteLine(“Hello world!”); WriteLine(“Another message”); } } Then, your code will compile. Note that, in C# 6.0, this will only … Read more

Long string interpolation lines in C#6

You can break the line into multiple lines, but I wouldn’t say the syntax looks nice any more. You need to use the $@ syntax to use an interpolated verbatim string, and you can place newlines inside the {…} parameters, like this: string s = $@”This is all { 10 } going to be one … Read more

How to enable C# 6.0 feature in Visual Studio 2013?

Under VS2013 you can install the new compilers into the project as a nuget package. That way you don’t need VS2015 or an updated build server. https://www.nuget.org/packages/Microsoft.Net.Compilers/ Install-Package Microsoft.Net.Compilers The package allows you to use/build C# 6.0 code/syntax. Because VS2013 doesn’t natively recognize the new C# 6.0 syntax, it will show errors in the code … Read more

Does C# 6.0 work for .NET 4.0?

Yes (mostly). C# 6.0 requires the new Roslyn compiler, but the new compiler can compile targeting older framework versions. That’s only limited to new features that don’t require support from the framework. For example, while you can use the string interpolation feature in C# 6.0 with earlier versions of .Net (as it results in a … Read more

What does the => operator mean in a property?

What you’re looking at is an expression-bodied member not a lambda expression. When the compiler encounters an expression-bodied property member, it essentially converts it to a getter like this: public int MaxHealth { get { return Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0; } } (You can verify this for yourself by pumping the code into a … Read more

What is the purpose of nameof?

What about cases where you want to reuse the name of a property, for example when throwing exception based on a property name, or handling a PropertyChanged event. There are numerous cases where you would want to have the name of the property. Take this example: switch (e.PropertyName) { case nameof(SomeProperty): { break; } // … Read more

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