C# Path Combine(String, String)

Description

Path Combine(String, String) Combines two strings into a path.

Syntax

Path.Combine(String, String) has the following syntax.


public static string Combine(
  string path1,
  string path2
)

Parameters

Path.Combine(String, String) has the following parameters.

  • path1 - The first path to combine.
  • path2 - The second path to combine.

Returns

Path.Combine(String, String) method returns The combined paths. 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.

Example

The following code example demonstrates using the Combine method.


/*w w w . j ava2s .  c o  m*/
using System;
using System.IO;

public class ChangeExtensionTest {

    public static void Main() {

        string path1 = "c:\\temp";
        string path2 = "subdir\\file.txt";

        string combination = Path.Combine(path1, path2);

        Console.WriteLine(combination);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter