Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Tojo Alex
PLUS
Tojo Alex
Courses Plus 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
229,786 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
PLUS
Tojo Alex
Courses Plus 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;
    }
}

}

Steven Parker
Steven Parker
229,786 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).