Managing the filesystem
Your applications will often need to perform input and output operations with files and directories in different environments. The System
and System.IO
namespaces contain classes for this purpose.
Handling cross-platform environments and filesystems
Let’s explore how to handle cross-platform environments and the differences between Windows and Linux or macOS. Paths are different for Windows, macOS, and Linux, so we will start by exploring how .NET handles this:
- Use your preferred code editor to create a new project, as defined in the following list:
- Project template: Console App/
console
- Project file and folder:
WorkingWithFileSystems
- Workspace/solution file and folder:
Chapter09
- Project template: Console App/
- In the project file, add an element to statically and globally import the
System.Console
class. - Add a new class file named
Program.Helpers.cs
. - In
Program.Helpers.cs
, add a partialProgram
class...