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 trialDaniel Hildreth
16,170 PointsCall read to end WebClient Challenge task 4
Hey I don't know what I'm doing with this code. I thought when you typed it out as return treehouse.ReadToEnd(); it called in the method and assigned it at the same time. That's what I took out of the video at least. Can someone help me with this?
using System;
using System.IO;
using System.Net;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetTreehouseHome());
}
public static string GetTreehouseHome()
{
string treehouse = "";
using(var webClient = new WebClient())
{
byte[] treehouseBytes = webClient.DownloadData("https://www.teamtreehouse.com");
using (var stream = new MemoryStream(treehouseBytes))
using (var reader = new StreamReader(stream))
{
return treehouse.ReadToEnd();
}
}
}
}
}
2 Answers
Steven Parker
231,268 PointsThe variable "treehouse" is a string. It has no ReadToEnd method.
The final task instructions are "Call the ReadToEnd method on the on the reader object, and assign the result of the method to the provided treehouse variable." Following those instructions will produce this line:
treehouse = reader.ReadToEnd();
But it also looks like you removed a line that the challenge started with, you'll need to put it back:
return treehouse;
Sara Rena Anderson
15,045 Points`` using System; using System.IO; using System.Net;
namespace Treehouse.CodeChallenges { class Program { static void Main(string[] args) { Console.WriteLine(GetTreehouseHome()); }
public static string GetTreehouseHome()
{
string treehouse = "";
using(var webClient = new WebClient())
{
byte[] treehouseBytes = webClient.DownloadData("https://www.teamtreehouse.com");
using (var stream = new MemoryStream(treehouseBytes))
using (var reader = new StreamReader(stream))
{
treehouse = reader.ReadToEnd();
}
}
return treehouse;
}
}
} ``