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 trialshawn khah
15,082 Pointsi dont know what's wrong!
Challenge Task 2 of 2
Inside the using block, write the contents of the first line of the file to the Console. Bummer! Did you write the contents of the file to the Console? Restart Preview Get Help Recheck work CodeChallenge.cs
1 DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory()); 2 string fileName = Path.Combine(directory.FullName, "secretmessage.txt"); 3 using (var reader = new StreamReader(fileName)) 4 { 5 Console.WriteLine(fileName); 6 }
DirectoryInfo directory = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
string fileName = Path.Combine(directory.FullName, "secretmessage.txt");
using (var reader = new StreamReader(fileName))
{
Console.WriteLine(fileName);
}
1 Answer
ALFRED MOHENU
1,499 PointsIn the code above, you can't pass filename into the console. In the using statement, you received the string filename and passed it into the StreamReader and stored everything in the variable "reader". That is what you should pass into the console. so
Console.WriteLine(reader);