New C# 6.0 String Interpolation statements don't compile [duplicate]

女生的网名这么多〃 提交于 2020-01-03 13:37:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!