I\'m surprised there\'s not an overload that can take a string array. Anyway, what is the best way to avoid nesting calls to Path.Combine?
pathValue = Path.Combi
If you already have an array or an IEnumerable
// I'm assuming that you've got an array or IEnumerable from somewhere
var paths = new string[] { path1, path2, path3, path4, path5, path6 };
string result = paths.Aggregate(Path.Combine);
If not, then write your own extension method to string...
public static class PathExtension
{
public static string CombinePathWith(this string path1, string path2)
{
return Path.Combine(path1, path2);
}
}
... that would allow you to chain these like this...
string result = path1.CombinePathWith(path2)
.CombinePathWith(path3)
.CombinePathWith(path4)
.CombinePathWith(path5)
.CombinePathWith(path6);