string-building

Building a directory string from component parts in C#

岁酱吖の 提交于 2019-12-01 04:45:25
If i have lots of directory names either as literal strings or contained in variables, what is the easiest way of combining these to make a complete path? I know of Path.Combine but this only takes 2 string parameters, i need a solution that can take any number number of directory parameters. e.g: string folder1 = "foo"; string folder2 = "bar"; CreateAPath("C:", folder1, folder2, folder1, folder1, folder2, "MyFile.txt") Any ideas? Does C# support unlimited args in methods? Does C# support unlimited args in methods? Yes, have a look at the params keyword. Will make it easy to write a function

Building a directory string from component parts in C#

一曲冷凌霜 提交于 2019-12-01 02:25:19
问题 If i have lots of directory names either as literal strings or contained in variables, what is the easiest way of combining these to make a complete path? I know of Path.Combine but this only takes 2 string parameters, i need a solution that can take any number number of directory parameters. e.g: string folder1 = "foo"; string folder2 = "bar"; CreateAPath("C:", folder1, folder2, folder1, folder1, folder2, "MyFile.txt") Any ideas? Does C# support unlimited args in methods? 回答1: Does C#