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
Dominik Huber4,631 Points
Can someone please explain this to me in more details? Console.WriteLine(Console.ReadLine()) makes no sense to me.
I have a few questions.
So the first code I don't get is this:
What exactly does the file.FullName return? Documentation says it returns the full path of the file. But why? I think we already have the full path with this code:
fileName = Path.Combine(directory.FullName, "data.txt");
Console.SetIn(reader); --> What is this doing exactly? It passes in the "Stream" and does what exactly?
So whenever I call Console.ReadLine() now I can't write anything to it, because the "StreamReader" passes in the string from the data.txt file? And it gets passed in every time I call Console.ReadLine(), until I close the stream? Please if someone could explain me this like I'm five would be very nice.
Steven Parker228,991 Points
The "SetIn" method determines where the input will come from. It's like setting a switch. If you choose a stream, it will take the input from the stream instead of from typing to the actual console.
If you want stream input and console input you would not redirect the console. Instead you can use the read methods of the stream itself.
James ChurchillTreehouse Teacher
In order to retrieve the information for the "data.txt" file, we need the full path to that file, which is what this code is doing:
var fileName = Path.Combine(directory.FullName, "data.txt");
Then, after we've retrieved the file information and verified that the file exists, we can use the FileInfo object's
FullName property to get the full path to the file. As you've noted, we already had the value on hand in the
fileName variable, so using the FileInfo
FullName property later on is a bit redundant.
I hope that helps.
Thank you, Steven! You are the person who adds value to Treehouse!