Hiermit kann man in .NET 2.0 in einer kleinen Funktion direkt mehrere Strings zusammen setzen.
/// <summary>
/// Combines a unlimited amount of parts to a path string.
/// </summary>
/// <param name="paths">The parts of the path to combine.</param>
/// <returns>Returns the combined path as string.</returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static string MultiCombine(params string[] paths)
{
if (paths == null)
{
throw new ArgumentNullException("paths", "paths cannot be null");
}
if (paths.Length < 2)
{
throw new ArgumentOutOfRangeException("paths", "paths cannot be less than 2");
}
string currentString = paths[0];
for (int i = 1; i < paths.Length; i++)
{
currentString = System.IO.Path.Combine(currentString, paths[i]);
}
return currentString;
}
5 Kommentare zum Snippet