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 Reading Data Console I/O

Why not use currentDirectory instead of directory.FullName for Path.Combine?

In the video, Carling first uses Directory.GetCurrentDirectory() to get a string containing directory's path. She then uses this string to make a DirectoryInfo object and uses its FullName property, which is also a string containing the path.

Could you not just use currentDirectory directly inside Path.Combine and cut out the middle man?

string currentDirectory = Directory.GetCurrentDirectory();
var fileName = Path.Combine(currentDirectory, "data.txt");

1 Answer

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Richard Oden it looks like that should be a working solution as well but I believe Carlings solution is intended to introduce the DirectoryInfo class