2

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.

3
  • 7
    You need VS 2015 to target C# 6 to utilize string interpolation.
    – krillgar
    Sep 27, 2016 at 17:30
  • Ed Plunkett, I have updated the question so you can see the error better. Hopefully you can remove the negatives. Thanks!
    – ADL
    Sep 27, 2016 at 17:37
  • @ADL I didn't downvote you. Sep 27, 2016 at 17:55

2 Answers 2

10

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.

1
  • Thanks! I kinda figured that's why.
    – ADL
    Sep 27, 2016 at 17:32
5

Visual Studio 2013 does not support interpolated strings. This is a feature from 2015.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.