ADL ADL - 2 months ago 25
C# Question

C#: Interpolated Strings- Visual Studio 2013?

enter image description hereI am looking at this example from the google cloud platform.

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

Specifically:

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


Console.WriteLine($ keeps giving me an error. I am using Visual Studio 2013 and cant seem to get this to work properly. Instead what i have to do is remove the dollar sign and + content as a variable.

I read this is a new syntax for C# version 6? Am i missing something? - Cant do this on Visual studio 2013?

Thanks for your responses!

I have updated my solution to provide a picture of the error. All it says is ) Expected.

It seems it does not recognize the dollar sign.

Answer

In order to use the new C# 6 capabilities you need to use VS 2015 instead. You can avoid that error by using

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

which is the C# 5 style of doing that.

Comments