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 the ternary operator inside an interpolated string?

According to the documentation: The structure of an interpolated string is as follows: { <interpolationExpression>[,<alignment>][:<formatString>] } The problem is that the colon is used to denote formatting, like: Console.WriteLine($”The current hour is {hours:hh}”) The solution is to wrap the conditional in parenthesis: var result = $”Descending {(isDescending ? “yes” : “no”)}”;

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