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 trialAaron Selonke
10,323 PointsWhy do we need to use the DirectoryInfo class?
There were a lot of new classes that I've not been familar with, so I was researching them one by one.
string currentDirectory = Directory.GetCurrentDirectory();
DirectoryInfo directory = new DirectoryInfo(currentDirectory);
var fileName = Path.Combine(directory.FullName, "SoccerGameResults.csv");
var fileContents = ReadFile(fileName);
It looks like in the code we wrote directory.FullName returns a string and is identical to the string currentDirectory.
That is, so far as I can tell, we didn't need to make the DirectoryInfo object at all.
2 Answers
Steven Parker
231,269 PointsIs the directory not also used for other things later in the code? If not, you may have found a bug!
You might want to submit this using the instructions on the Support page.
babasariffodeen
6,475 PointsI also notice that there wasn't a need to use the DirectoryInfo class. Although I know that using DirectoryInfo gives us lots of instance methods, they were not used in the video.
Using Directory.GetCurrentDirectory() was sufficient to get the working directory path.
It did confuse/clutter things a bit.