Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 如何使用c#只存储文件名而不是整个路径?_C# 4.0 - Fatal编程技术网

C# 4.0 如何使用c#只存储文件名而不是整个路径?

C# 4.0 如何使用c#只存储文件名而不是整个路径?,c#-4.0,C# 4.0,在我的c代码中,我正在读取一个变量的文件名,它们可能类似于c:\users\documetnts\test.bin 但是,我如何摆脱整个路径呢?我只想存储文件名test.bin,而不是整个路径 我该怎么做 使用System.IO命名空间中类中的方法: class Program { static void Main(string[] args) { string path = @"C:\users\documetnts\test.bin"; Con

在我的c代码中,我正在读取一个变量的文件名,它们可能类似于c:\users\documetnts\test.bin 但是,我如何摆脱整个路径呢?我只想存储文件名test.bin,而不是整个路径

我该怎么做

使用System.IO命名空间中类中的方法:

class Program
{
    static void Main(string[] args)
    {
        string path = @"C:\users\documetnts\test.bin";

       Console.WriteLine( Path.GetFileName(path));
       Console.ReadLine();
    }
}

如何“读取变量的文件名”?