Path.Combine uses the values โโof Path.DirectorySeperatorChar and Path.VolumeSeparatorChar , and they are defined by class libraries at runtime, so if you write your code using only Path.Combine tags, Environment.SpecialFolder values, etc. go ahead, it will work fine everywhere, since Mono (and, presumably, any .NET runtime) implements its own way of getting and building these paths for any platform on which it works. (For example, your second example returns /server/mydir for me, but the first example gives c:\/windows )
If you want UNIX hard code to be defined in all cases, Path.Combine does not buy anything: Console.WriteLine ("/server/mydir"); does what you want in the OP.
As Hans said, different file systems have different rules for allowed characters, path lengths, etc., so the best practice, as with any cross-platform programming, is to limit yourself to using the intersection of allowed functions between file systems, which you are targeting. See also case sensitivity issues.
Matt enright
source share