问题
I am trying to implement some of the features in this video but I'm not having much luck with the new String Interpolation syntax (I have everything else working, at least that's in this code).
I am using Visual Studio 2015 CTP6, I have configured it to use .NET 4.6 and have gone into the Build options to make sure I was specifying C# 6.0. I have also followed the instructions here.
Here is my code:
using System;
using static System.Math;
namespace NewCsharp6Features
{
public class C6Point
{
public int X { get; }
public int Y { get; }
public double Distance => Sqrt(X * X + Y * Y);
public C6Point(int x, int y) { X = x; Y = y; }
public override string ToString()
{
return "(\{X}, \{Y})";
}
}
}
I am getting two of this compilation error:
CS1009 | Unrecognized escape sequence
Any idea what I'm doing wrong, here?
回答1:
You need to proceed the string with a $
public override string ToString()
{
return $"({X}, {Y})";
}
来源:https://stackoverflow.com/questions/29154868/new-c-sharp-6-0-string-interpolation-statements-dont-compile