扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

c#相对路径获取的方法是什么

扬州沐宇科技
2024-03-04 18:53:07
c#

在C#中获取相对路径的方法通常使用Path类的Combine方法。该方法可以将基础路径和相对路径组合在一起,得到完整的路径。示例如下:

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string basePath = @"C:\Users\Public";
        string relativePath = @"Documents\MyFile.txt";

        string fullPath = Path.Combine(basePath, relativePath);

        Console.WriteLine(fullPath);
    }
}

在上面的示例中,basePath是基础路径,relativePath是相对路径,使用Path.Combine方法将它们组合在一起得到完整的路径。

扫码添加客服微信