PathCombine

public static string PathCombine(this IEnumerable<string> pathParts)
        {
            string joinedPath = "";
            foreach(string pathPart in pathParts)
                joinedPath = Path.Combine(joinedPath,pathPart);

            return joinedPath;
        }
Example:
string path = new[] { s1, s2, s3 }.PathCombine();
string path = someIEnumerableString.PathCombine();

Description

Combines an IEnumerable<string> using Path.Combine(), which will use the separator character that is correct for the platform used. It is a shorter and more correct way to combine paths than just using + "\\" + . Requires "using System.IO;" at the top of your extension method class.

Details

Double click on the code to select all.

 

;