C# 6.0 TFS Builds

For the compilation step, you have a couple of options: You can reference the Microsoft.Net.Compilers NuGet package on a per-project basis to use that version of the compilers. You can install the Microsoft Build Tools package that is part of the VS 2015 CTP package without installing all of VS. However, as @MrHinsh notes, these … 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

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 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

What does the => operator mean in a property or method?

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

How to implement INotifyPropertyChanged in C# 6.0?

After incorporating the various changes, the code will look like this. I’ve highlighted with comments the parts that changed and how each one helps public class Data : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { //C# 6 null-safe operator. No need to check for event listeners //If there … Read more

C#6.0 string interpolation localization

An interpolated string evaluates the block between the curly braces as a C# expression (e.g. {expression}, {1 + 1}, {person.FirstName}). This means that the expressions in an interpolated string must reference names in the current context. For example this statement will not compile: var nameFormat = $”My name is {name}”; // Cannot use *name* // … Read more