C# 程序用于在 C# 中获取文件扩展名
csharpprogrammingserver side programming更新于 2025/9/16 5:04:00
要处理文件路径,在 C# 中使用 Path 类。
在字符串 − 中设置文件名
string myPath = "D:\
ew\quiz.txt";
现在,要获取扩展名,请使用 GetExtension() 方法 −
Path.GetExtension(myPath)
这是完整的代码 −
示例
using System;
using System.IO;
namespace Demo {
class Program {
static void Main(string[] args) {
string myPath = "D:\
ew\quiz.txt";
Console.WriteLine(Path.GetExtension(myPath));
}
}
}
输出
.txt

