views:

105

answers:

3

What’s the .net namespace constant thingy for the forward slash "/"

So instead of:

somePath + "/" + someFile

I can do:

somePath + .net.namespace.forwardslash + someFile

Not really much difference but maybe neater?

A: 

Just use a forward slash if that's what you need, but if you're trying to combine a file name and a path, just use System.IO.Path.Combine().

Dave Markle
This is not correct: System.IO.Path.DirectorySeparatorChar. But I didn't downvote because you mentioned Path.Combine, though.
Martinho Fernandes
He is correct. On Windows Path.DirectorySeparatorChar returns the backslash, in Mono it will be probably a slash when running on an unixoid environment. Using Path.Combine is the correct approach.
Marc Wittke
+9  A: 

System.IO.Path.DirectorySeparatorChar is what you want i think.

BTW, a saner way to do it is to use System.IO.Path.Combine(somePath,someFile).

axel_c
excellent stuff :-)
Rob
so many upvotes and even an accept for a misleading answer. The Path.DirectorySeparatorChar returns "a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization" (MSDN) - therefore it WON'T be the forward slash in most .net cases. However, if you are just asking how to concatenate directory path and file name in a safe way, then the answer is correct (although the question is wrong)
Marc Wittke
+1  A: 

You should go with System.IO.Path.DirectorySeparatorChar

Rubens Farias