做时间的朋友😭
C# Path.Combine方法代码示例

C# Path.Combine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
string s1 = Path.Combine("D:", "file.txt"); // D:file.txt

string s2 = Path.Combine("D:\\", "file.txt"); // D:\file.txt
string s3 = Path.Combine("D:\\dir", "file.txt"); // D:\dir\file.txt
string s4 = Path.Combine("D:\\dir\\", "file.txt"); // D:\dir\file.txt

string s5 = Path.Combine("D:", "/file.txt"); // /file.txt
string s6 = Path.Combine("D:\\", "\\file.txt"); // \file.txt
string s7 = Path.Combine("D:\\dir\\", "/file.txt"); // /file.txt
string s8 = Path.Combine("D:\\dir\\", "\\file.txt"); // \file.txt

var fileDir = "C:\\Windows";
var fileDir2 = "C:\Windows"; //编译器直接报错
var fileName = "file.txt";

var filePath1= Path.Combine(@"C:\Windows", fileName);
// sendDir、fileName不能为空
var filePath2 = Path.Combine(fileDir, fileName);
if (File.Exists(filePath1))
{
File.Delete(filePath);
}
C#
随便记记01
C#常用的排序方法
© 2022 Sk8erBoi
Powered by hexo | Theme is blank