C# C# Streams and Data Processing Streaming Data on the Net Become Zen

Tojo Alex
PRO
Tojo Alex
Pro Student 13,331 Points

I do not understand my error

Could you kindly explain what is wrong with this script and why it won't let me pass.

Program.cs
using System;
using System.IO;
using System.Net;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(BecomeZen());
        }
        public static string BecomeZen()
        {
            string zenResponse = "webClient.DownloadString("https://api.github.com/zen");

            using(var webClient = new WebClient())
            {
            webClient.Headers.Add("User-Agent", "CodeChallenge");
            }

            return zenResponse;
        }
    }
}

4 Answers

Steven Parker
Steven Parker
177,726 Points

Remember that "webClient" only exists inside the "using" block. So you'll need to call "webClient.DownloadString" from inside the block.

Also, watch for unbalanced quote marks when you create that assignment inside.

Tojo Alex
PRO
Tojo Alex
Pro Student 13,331 Points

I fixed the unbalanced quote marks. So are you saying move the current string into the "using" block because when I do that it give me this : Did you call the 'DownloadString' method on the 'webClient' object? .

```using System; using System.IO; using System.Net;

namespace Treehouse.CodeChallenges { class Program { static void Main(string[] args) { Console.WriteLine(BecomeZen()); } public static string BecomeZen() {

        using(var webClient = new WebClient())
        {
        webClient.Headers.Add("User-Agent", "CodeChallenge");
            string zenResponse = "webClient.DownloadString"("https://api.github.com/zen");
        }

        return zenResponse;
    }
}

}

Tojo Alex
PRO
Tojo Alex
Pro Student 13,331 Points

I worked out a solution. Thanks Steven.

Steven Parker
Steven Parker
177,726 Points

Good deal. :+1:

For the benefit of future readers, "zenResponse" should only be assigned inside the "using" block, it still needs to be declared in the method itself (the original declaration can remain as-is).