Jax*_*ian 5 c# string-interpolation c#-6.0 visual-studio-2015
我正在尝试实现此视频中的一些功能,但我对新的字符串插值语法没有太多运气(我还有其他所有工作,至少在这段代码中是这样).
我正在使用Visual Studio 2015 CTP6,我已将其配置为使用.NET 4.6并已进入Build选项以确保我指定C#6.0.我也按照这里的说明进行操作.
这是我的代码:
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})";
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到了两个这样的编译错误:
CS1009 | 无法识别的转义序列
知道我做错了什么,在这里?
小智 9
你需要用$来继续字符串
public override string ToString()
{
return $"({X}, {Y})";
}
Run Code Online (Sandbox Code Playgroud)