Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
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