Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer Test with flashcards and multiple choice questions. Each question comes with hints and explanations. Boost your confidence for the exam day!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What is one method to create a directory in C#?

  1. Directory.CreateDirectory()

  2. Directory.Create()

  3. DirectoryInfo.Create()

  4. Directory.CreateNew()

The correct answer is: Directory.CreateDirectory()

The method to create a directory in C# is achieved through the Directory.CreateDirectory() method. This method is part of the System.IO namespace and is specifically designed for creating directories. When this method is called, it not only creates a specified directory but also any subdirectories that might be needed along the way. If the directory already exists, it does nothing and simply returns a reference to the existing directory. The strengths of using Directory.CreateDirectory() include its ability to handle multiple directories in a single call, which can simplify code and avoid errors related to directory creation processes. Additionally, it provides a straightforward means of verifying whether the directory was successfully created or if it already existed without additional checks. Other methods related to directory handling, while relevant, do not serve the same purpose. Directory.Create(), for example, is not a defined method in the .NET framework. DirectoryInfo.Create() can create directories, but it is tied to an instance of a DirectoryInfo object, which requires additional steps to set up. Directory.CreateNew() does not exist within the .NET framework either. Therefore, Directory.CreateDirectory() stands out as the correct and most efficient choice for creating directories in C#.