新的C#6.0字符串插值语句不编译

时间:2015-03-19 20:57:39

标签: c# visual-studio-2015 string-interpolation c#-6.0

我正在努力实现this video中的一些功能,但我对新的字符串插值语法没有太多运气(我还有其他一切正常工作,至少在这段代码)。

我正在使用Visual Studio 2015 CTP6,我已将其配置为使用.NET 4.6并已进入Build选项以确保我指定C#6.0。我还有followed the instructions here

这是我的代码:

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})";
        }
    }
}

我收到了两个这样的编译错误:

  

CS1009 |无法识别的转义序列

知道我做错了什么,这里?

1 个答案:

答案 0 :(得分:9)

您需要使用$

继续字符串
        public override string ToString()
        {
            return $"({X}, {Y})";
        }