C# char "//" path separator

Catherine picture Catherine · Jan 4, 2011 · Viewed 28.5k times · Source

Is there possible to use char "//" another there I did it? I looked for in Path, but I can't find it.

  string separator = "//";

I mean '/'.

I used:

static string sep = System.IO.Path.PathSeparator.ToString();

but it returns: ';'. Why?

Answer

Ergwun picture Ergwun · Jul 13, 2012

Path.DirectorySeparatorChar gives you the character used to separate directories in a path, i.e. you use it in paths.

Path.PathSeparator gives you the character used to separate paths in environment variables, i.e. you use it between paths.

For example, your system's PATH environment variable will typically list multiple paths where the OS will look for applications to run.

On Windows, Path.PathSeparator is ;, and Path.DirectorySeparatorChar is \. Two paths would be stored in an environment variable like this:

set PATH="C:\first\path;C:\second\path"