新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

c#相对路径获取的有哪些方法,c#如何获取相对路径

发布时间:2024-03-04 18:53:07

c#相对路径获得的有哪些方法

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

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string basePath = @"C:UsersPublic";
        string relativePath = @"DocumentsMyFile.txt";

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

        Console.WriteLine(fullPath);
    }
}

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