租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

C#的directory.exists方法如何使用

发布时间:2023-08-03 08:29:16

C#的directory.exists方法如何使用

在C#中,可使用`Directory.Exists()`方法来检查指定的目录是否是存在。该方法返回一个布尔值,表示目录是否是存在。
以下是使用`Directory.Exists()`方法的示例:
```csharp
string path = @"C:ExampleDirectory";
if (Directory.Exists(path))
{
Console.WriteLine("目录存在");
}
else
{
Console.WriteLine("目录不存在");
}
```
在上面的示例中,我们首先指定了一个目录路径`path`。然后,使用`Directory.Exists()`方法检查该目录是否是存在。如果存在,我们输出"目录存在";如果不存在,我们输出"目录不存在"。