C#:Interpolated Strings- Visual Studio 2013?

ADL*_*ADL 1 c#

在此输入图像描述我正在从谷歌云平台看这个例子.

https://cloud.google.com/storage/docs/json_api/v1/json-api-dotnet-samples

特别:

public void DownloadStream(string bucketName)
{
    StorageService storage = CreateStorageClient();

    using (var stream = new MemoryStream())
    {
        storage.Objects.Get(bucketName, "my-file.txt").Download(stream);

        var content = Encoding.UTF8.GetString(stream.GetBuffer());

        Console.WriteLine($"Downloaded my-file.txt with content: {content}");
    }
}
Run Code Online (Sandbox Code Playgroud)

Console.WriteLine($一直给我一个错误.我使用Visual Studio 2013并且似乎无法让它正常工作.相反,我要做的是删除美元符号和+内容作为变量.

我读到这是C#版本6的新语法?我错过了什么吗? - 不能在Visual Studio 2013上这样做吗?

谢谢你的回复!

我已更新我的解决方案,以提供错误的图片.它只是说)预期.

它似乎无法识别美元符号.

Pab*_*lde 9

要使用新的C#6功能,您需要使用VS 2015.您可以通过使用来避免该错误

Console.WriteLine(String.Format("Downloaded my-file.txt with content:{0}", content));
Run Code Online (Sandbox Code Playgroud)

这是C#5的风格.


小智 5

Visual Studio 2013 不支持内插字符串。这是 2015 年的一项功能。