Linux 拨号vps windows公众号手机端

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

lewis 9年前 (2016-11-29) 阅读数 8 #程序编程
文章标签 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方法将它们组合在一起得到完整的路径。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门