System.io.DirectorySeparatorChar returns the character "\" while System.io.AltDirectorySeparatorChar returns "/"
to be more specific what is the job of System.Io.AltDirectorySeparatorChar and when we use it?
System.io.DirectorySeparatorChar returns the character "\" while System.io.AltDirectorySeparatorChar returns "/"
to be more specific what is the job of System.Io.AltDirectorySeparatorChar and when we use it?
My understanding is that DirectorySeparatorChar is platform-specific default separator, while AltDirectorySeparatorChar is platform-independent universal separator.
On Windows : DirectorySeparatorChar is backslash, AltDirectorySeparatorChar is forward slash
On Unix-based : Both are forward slash
It is because Windows natively prefers backslash but also supports forward slash, while Unix-based systems only support forward slash. Practically, it means you can use either one.
I would personally prefer DirectorySeparatorChar, because I simply prefer backslash on Windows. But perhaps the best is to use Path.Combine and let the choice up to this method.
From the documentation (https://learn.microsoft.com/en-us/dotnet/api/system.io.path.altdirectoryseparatorchar)
You can use alt separator in your path strings the same way as you use normal separator. Like this:
And the output: