开发者

combine three parts

Path.combine can only combine two string, is there a qucik way to combine开发者_运维百科 three and four strings?


Upgrade to .Net 4.0, which adds the overloads you're looking for.


If you're stuck in .Net 3.5, you can call Path.Combine multiple times.

If you have an IEnumerable<string>, you can write

string path = strings.Aggregate(Path.Combine);


I'm not a C# programmer, but something like

string s = Path.Combine("str1", Path.Combine("str2", Path.Combine("str3", "str4")));

Seems obvious.


If you can upgrade to .NET 4.0 it has what you are looking for.

Otherwise:

public string Combine(IEnumerable<string> strings) {
    return strings.Aggregate((x, y) => Path.Combine(x, y));
}

and

public string Combine(params string[] strings) {
    return Combine((IEnumerable<string>)strings);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜