Home  >  Article  >  Backend Development  >  DirectoryNotFoundException in C#

DirectoryNotFoundException in C#

WBOY
WBOYforward
2023-09-21 16:21:031128browse

C# 中的 DirectoryNotFoundException

DirectoryNotFoundException occurs if the directory you are looking for does not exist.

Here, we try to use the GetDirectories() method to find a directory that does not exist.

Example

using System.IO;
using System;
class Program {
   static void Main() {
      Directory.GetDirectories("D:\ew\");
   }
}

Since the directory "D:\

ew" does not exist, the above code will generate the following exception.

Unhandled Exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path

The above is the detailed content of DirectoryNotFoundException in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete