Concatenates two
path strings.
[Edit]
Parameters
- path1
- A string containing the first path.
[Edit]
- path2
- A string containing the second path.
[Edit]
Returns
A string containing
path1 followed by path2.
If one of the specified paths is a zero length string, this method returns the
other path. If path2 contains an absolute path, this method returns
path2.
[Edit]
Exceptions
Remarks
Example
The following example demonstrates using the
Combine method on a Windows system.
C# Example |
using System;
using System.IO;
class CombineTest {
public static void Main() {
string path1, path2;
Console.WriteLine("Dir char is {0} Alt dir char is {1}",
Path.DirectorySeparatorChar,
Path.AltDirectorySeparatorChar
);
path1 = "foo.txt";
path2 = "\\ecmatest\\examples";
Console.WriteLine("{0} combined with {1} = {2}",path1, path2 , Path.Combine(path1,
path2));
path1 = "\\ecmatest\\examples";
path2 = "foo.txt";
Console.WriteLine("{0} combined with {1} = {2}",path1, path2 , Path.Combine(path1,
path2));
}
}
|
The output is
Dir char is \ Alt dir char is /
foo.txt combined with \ecmatest\examples = \ecmatest\examples
\ecmatest\examples combined with foo.txt =
\ecmatest\examples\foo.txt
Requirements
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0