Monday, April 14, 2014

Better way of combining path in C#

You could do string operation to construct path as below :

string path = path1 + "\\" + path2;

However, more portable and cleaner way would be to use Path.Combine as below :

Path.Combine(path1, path2);

The above avoid you to make manually ensuring the correctness of path separators.