在C#中,可以使用Path.Combine()方法来获取指定文件的完整路径。以下是一个示例代码,用于获取 C:\AA\C.TXTC:\C.TXT 的完整路径:

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string directory = @"C:\AA";
        string fileName = "C.TXT";

        string fullPath1 = Path.Combine(directory, fileName);
        Console.WriteLine(fullPath1);

        string fullPath2 = Path.Combine(@"C:\", fileName);
        Console.WriteLine(fullPath2);
    }
}

输出结果为:

C:\AA\C.TXT
C:\C.TXT

请注意,Path.Combine()方法会自动处理斜杠和反斜杠的差异,并生成正确的路径。在示例代码中,我们使用了@符号来指示字符串中的反斜杠 \ 不要被视为转义字符

c#获取 CAACTXT CTXT

原文地址: http://www.cveoy.top/t/topic/ij6e 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录