ADL ADL - 1 year ago 168
C# Question

C#: Interpolated Strings- Visual Studio 2013?

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


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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download